“语法错误 (逗号) 在查询表达式 'id=20, 21”,怎么处理这个逗号?

wishingwings 2003-08-20 04:10:13
我用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 行

怎末处理,请教呀!


...全文
402 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
mmcgzs 2004-01-18
  • 打赏
  • 举报
回复
如果程序运行不正确试试下面的语句:
temp=replac(temp,", "," or id=")
mmcgzs 2004-01-18
  • 打赏
  • 举报
回复
楼上的楼上真是高手
genuis 2004-01-18
  • 打赏
  • 举报
回复
temp=replac(temp,","," or id=")

这个方法不错

超级大笨狼 2004-01-18
  • 打赏
  • 举报
回复
这样就可以了,不用split,不会出错。temp为空的时候要判断一下。
最好在提交的时候就规范一下,不要出现只有逗号没有数字的情况。
temp=trim(request(temp))
if temp<>"" then temp=" where id=" & temp
temp=replac(temp,","," or id=")
sql="select * from book " & temp
空闲独处 2003-08-20
  • 打赏
  • 举报
回复
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等等的记录都加进去呢?没有验证过,不太清楚。
zhxhjj 2003-08-20
  • 打赏
  • 举报
回复
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&")"
peytonzwt 2003-08-20
  • 打赏
  • 举报
回复
在sql语句里用in()
sql="select * from book where id in ("&temp&")"
sunyc 2003-08-20
  • 打赏
  • 举报
回复
当在上一页该变量被重复赋值会传来多个值,中间用逗号隔开。
awaysrain 2003-08-20
  • 打赏
  • 举报
回复
用in
sql="select * from book where id in ("
sql=sql &temp & ")"

28,391

社区成员

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

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