日期:2014-05-16  浏览次数:20951 次

sql单引号问题
 
 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'") 

搞了半天没整明白,都要崩溃了。求助来了
------解决方案--------------------
你 ".... InfoSys1=''" & id & "''"
得到的是 InfoSys1=''id‘’
显然是不对的
InfoSys1='id‘ 才是正确的

在这里,单引号是字符串边界,要转义的是字符串内的单引号
------解决方案--------------------
你打印出
 "select * from InfoSys where InfoSys6 = 241 and InfoSys1='" & id & "'"
的结果看一下是否正确
------解决方案--------------------
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&'") 
------解决方案--------------------
接分  接分