SQL Server 中Update的问题?

giszj 2004-09-20 06:19:46
本人用ADO连接了Sql server后,要对表A中符合条件的记录的字段X的值更改
如下:
dim con as new adodb.connection
....
dim str as string
dim mysql as string
str="myvalue"
mysql="update A set x=" & str & "2" & "where x=" str
con.execute mysql
问题来了:
程序老是提示”列名myvalue2无效?!“
天哪我的值怎么成了列名了呢?
即窗口中的值:update A set x=myvalue2 where x=myvalue
怎么不是:update A set x='myvalue2' where x='myvalue'
请问究竟是怎么回事啊?如何解决这个问题呢?



...全文
107 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wtadminxjeri 2004-09-20
  • 打赏
  • 举报
回复
Dim str As String
Dim mysql As String
str = "myvalue"
mysql = "update A set x='" & str & "2" & "' where x='" & str & "' "
zjcxc 2004-09-20
  • 打赏
  • 举报
回复
dim con as new adodb.connection
....
dim str as string
dim mysql as string
str="myvalue"
mysql="update A set x='" & str & "2'" & "where x='" str & "'" --你自己少写了嘛
con.execute mysql
99831323 2004-09-20
  • 打赏
  • 举报
回复
mysql="update A set x=" & str & "2" & "where x=" str
-->
mysql="update A set x='" & str & "2'" & "where x='" & str & "'"

你不给它加引号,它当然没引号

wtadminxjeri 2004-09-20
  • 打赏
  • 举报
回复
字符类型的值更新要加单引号,你的更新语句放到查询分析器就成为以下的句子了
-----------------------------------------
update A set x= myvalue2 where x=myvalue

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧