“语法错误 (逗号) 在查询表达式id=20, 21”,怎么处理这个逗号?
来源:asp之家 时间:2009-09-18 14:52:00
我用asp+access写程序,
sql="select * from book where id="
sql=sql &temp
temp是从上个页面传来的显示记录的标号(最多可以选2条记录)
dim temp
temp=Request("bookchange")
if temp="" then
temp=1
end if
如果temp传来的是2个数字,我测试了一下,系统报错:
错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] 语法错误 (逗号) 在查询表达式 'id=20, 21' 中。
/bookmanage/lendbook.asp, 第 14 行
怎末处理,请教呀!
用in
sql="select * from book where id in ("
sql=sql &temp & ")"
在sql语句里用in()
sql="select * from book where id in ("&temp&")"
aa=split(temp,',')
for i=0 to ubound(aa)
te=te&"'"&aa(i)&"',"
next
te=left(te,len(te)-1)
sql="select * from book where id in ("&te&")"
StrArr = split(temp, ",")
sql="select * from book where"
For i = 0 To UBound(StrArr)
StrSQL = StrSQL & "id = '" & Trim(StrArr(i)) & "'"
If i < UBound(StrArr) Then StrSQL = StrSQL & " OR "
Next
这种应该会比较有效,用in的话,当传过来的是2135,3521的话,会不会连21,13,15等等的记录都加进去呢?没有验证过,不太清楚。
这样就可以了,不用split,不会出错。temp为空的时候要判断一下。
最好在提交的时候就规范一下,不要出现只有逗号没有数字的情况。
temp=trim(request(temp))
if temp<>"" then temp=" where id=" & temp
temp=replac(temp,","," or id=")
sql="select * from book " & temp
temp=replac(temp,","," or id=")
这个方法不错
如果程序运行不正确试试下面的语句:
temp=replac(temp,", "," or id=")
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
javascript验证IP地址等验证例子
css特性:空白外边距互相叠加
![](https://img.aspxhome.com/file/UploadPic/20106/21/100530a-82s.jpg)
mysql查询一天,查询一周,查询一个月的数据
asp实现本周的一周时间列表的代码
用 jQuery 來做图片伪浮水印
ASP连接11种数据库语法总结
ASP+Access系统的安全隐患及对策
Chrome V8 引擎对 sort 的优化
使用 XML 文件记录操作日志
oracle 集合
使用xml http为网站增加域名查询功能
DNS优化的原理和方法
![](https://img.aspxhome.com/file/20230519/1684460150434038s.jpg)
SQL Server 数据库操作实用技巧锦集
在MySQL数据库中如何来复位根用户的密码
SQL Server数据库对上亿表的操作
FCKeditor技巧之在按钮旁边加文字
![](https://img.aspxhome.com/file/UploadPic/200710/10/20071010132030615s.png)