SQL更新语法
你如何做更新声明?
我想用这个字符串theUserid更新UserID,我想用同一个表(图片)中的fileuploadpaths(字符串)更新图片路径
OdbcCommand cmd = new OdbcCommand("UPDATE Pictures
SET ('" + theUserId + "','" + fileuploadpaths + "')
WHERE (UserID, picturepath)", cn);
不确定它是否
UPDATE Pictures
SET UserID = "+ theUserid +"
picturepath="+ fileuploadpaths +"
Where UserID = theUserid
picturepath = something already in my db?
编辑:
我尝试过这个:
OdbcCommand cmd = new OdbcCommand("UPDATE Pictures SET picturepath ='" + fileuploadpaths + "' WHERE UserId = '" + theUserId + "')", cn);
但我得到了错误:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行 ')' 附近使用的正确语法
How do you do an update statement?
I would like to update UserID with this string theUserid and I would like to update picturepath with fileuploadpaths(string) in the same table (Pictures)
OdbcCommand cmd = new OdbcCommand("UPDATE Pictures
SET ('" + theUserId + "','" + fileuploadpaths + "')
WHERE (UserID, picturepath)", cn);
Not sure if its
UPDATE Pictures
SET UserID = "+ theUserid +"
picturepath="+ fileuploadpaths +"
Where UserID = theUserid
picturepath = something already in my db?
EDIT:
Ive tryed this:
OdbcCommand cmd = new OdbcCommand("UPDATE Pictures SET picturepath ='" + fileuploadpaths + "' WHERE UserId = '" + theUserId + "')", cn);
but I get the error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
用途:
虽然参数有名称,但它们是绑定变量。这意味着指定的值需要按照“?”的位置顺序排列。占位符,从查询字符串的第一个字符开始(“更新...”)。
参考
Use:
Though the parameters have names, they are bind variables. Meaning the value specified needs to be in the position order of the "?" placeholders, starting from the first character of the query string ("Update...").
Reference
你可能想要这样的东西:
You probably want something like this:
您只是通过用户 ID 进行查询,对吗?在这种情况下,它不需要包含在
UPDATE
子句中,并且picturepath
不需要位于WHERE
中条款。请参阅 MySQL
UPDATE
文档更多的。You are just querying by the user ID, correct? In that case, it doesn't need to be included in your
UPDATE
clause, and thepicturepath
doesn't need to be in theWHERE
clause.See the MySQL
UPDATE
docs for more.