sql单引号问题

q574502923 2014-03-29 11:35:08
 
function getdata(id)
Set MyDB=New YKTDB
Set MyDB.Conn=MyConn.Conn
set rs=MyDB.Find("select * from InfoSys where InfoSys6 = 241 and InfoSys1=''" & id & "''")
Set MyDB=nothing
i=0
do while not rs.eof
i=i+1
rs.movenext
loop
getdata=i
end function

上面这段代码sql拼接有问题,输出的条数为0
如果把sql换成下面这样的就没有问题,应该是拼接sql单引号的问题。

set rs=MyDB.Find("select * from InfoSys where InfoSys6 = 241 and InfoSys1='199'")

搞了半天没整明白,都要崩溃了。求助来了
...全文
194 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangtututu 2014-03-31
  • 打赏
  • 举报
回复
接分 接分
xuzuning 2014-03-30
  • 打赏
  • 举报
回复
你打印出 "select * from InfoSys where InfoSys6 = 241 and InfoSys1='" & id & "'" 的结果看一下是否正确
q574502923 2014-03-30
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
你 ".... InfoSys1=''" & id & "''" 得到的是 InfoSys1=''id‘’ 显然是不对的 InfoSys1='id‘ 才是正确的 在这里,单引号是字符串边界,要转义的是字符串内的单引号
如果写成这样的话

set rs=MyDB.Find("select * from InfoSys where InfoSys6 = 241 and InfoSys1='" & id & "'") 
它就报错了 An error occurred on the server when processing the URL. Please contact the system administrator.
xuzuning 2014-03-30
  • 打赏
  • 举报
回复
你 ".... InfoSys1=''" & id & "''" 得到的是 InfoSys1=''id‘’ 显然是不对的 InfoSys1='id‘ 才是正确的 在这里,单引号是字符串边界,要转义的是字符串内的单引号
任何人任何 2014-03-30
  • 打赏
  • 举报
回复
set rs=MyDB.Find("select * from InfoSys where InfoSys6 = 241 and InfoSys1='" & id & "'") 修改为: set rs=MyDB.Find("select * from InfoSys where InfoSys6 = 241 and InfoSys1='"&id&'")

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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