Update语句中的表名不能用参数代替吗
问题描述:
asp连接access数据库中
dim strSql, strSql2
strSql="Update 东方不败 Set Sfhwhy='Y' where name='"&hy&"'"
conn2.Execute(strSql)
上述语句中的表名是东方不败,我们直接写到了查询语句中,是可行的,但遗憾的是,用参数来替代就是不行
Dim km
km="东方不败"
dim strSql, strSql2
strSql="Update "& km & "Set Sfhwhy='Y' where name='"&hy&"'"
conn2.Execute(strSql)
把参数赋值给km后,这就不行了
dim strSql, strSql2
strSql="Update "& "东方不败" & "Set Sfhwhy='Y' where name='"&hy&"'"
conn2.Execute(strSql)
还是直接用字符串,只不过是以字符串连接的方式,也是不行,不明白是什么原因,请高手指点下哈
答
可以,set前别缺空格,你打一下strSql
strSql="Update "& km & " Set Sfhwhy='Y' where name='"&hy&"'"
答
可以,但是Set前缺少一个空格。
答
用存储过程,可以带参数,而且性能还更好
答
strSql="Update "& km & " Set Sfhwhy='Y' where name='"&hy&"'"