主题:" ' 的问题
endlessrain [专家分:10] 发布于 2007-05-21 21:23:00
<%px=request.QueryString("sort")
if px="" then
px="id"
end if
set rs=server.CreateObject("adodb.recordset")
if request.form("submit")<>empty then
dim a
dim b
dim c
a=request.Form("select2")
b=request.Form("guanjianci")
c=request.Form("select")
if c=jingque then
rs.open "select * from product where '"&a&"'='"&b&"' order by "&px&"",conn,1,1
else
rs.open "select * from product where '"&a&"'like '%'"&b&"'%' order by "&px&"",conn,1,1
end if
else
rs.open "select * from product order by "&px&"",conn,1,1
end if
%>
当条件中全是变量是" '应该如何使用啊?
上面好多错误,如何改啊?
回复列表 (共9个回复)
沙发
yaozheng [专家分:28410] 发布于 2007-05-21 22:49:00
单引号只是针对字符串而言的。所以这样写是错误的,字段不需要单引号。
rs.open "select * from product where "&a&"='"&b&"' order by "&px&"",conn,1,1
rs.open "select * from product where '"&a&"'like '%'"&b&"'%' order by "&px&"",conn,1,1
这句应该这样写
rs.open "select * from product where "&a&" like '%"&b&"%' order by "&px&"",conn,1,1
板凳
endlessrain [专家分:10] 发布于 2007-05-22 12:36:00
不是说 双引号 里面的 双引号要变成单引号的吗?
3 楼
endlessrain [专家分:10] 发布于 2007-05-23 10:41:00
还有这语句好象控制不了
if c=jingque then
rs.open "select * from product where '"&a&"'='"&b&"' order by "&px&"",conn,1,1
else
rs.open "select * from product where '"&a&"'like '%%'"&b&"'%%' order by "&px&"",conn,1,1
end if
if rs.eof then
server.transfer "error.asp"
end if
选择精确(jingque)时,数据库中没有查找到时,它不出现错误,而是执行了else下的模糊查找,把和这相关的找了出来,何解?我用的是access 数据库
4 楼
merry05 [专家分:8920] 发布于 2007-05-23 11:13:00
我与碰到过类似问题,ASP对SQL的操作中,对字段加上引号不会报错,但会出现一些奇奇怪怪的现象
5 楼
endlessrain [专家分:10] 发布于 2007-05-23 13:14:00
你是怎么解决的啊
6 楼
liulei001 [专家分:12820] 发布于 2007-05-23 13:50:00
Str = Replace(Str, "'","''")
7 楼
endlessrain [专家分:10] 发布于 2007-05-23 20:11:00
什么意思?
替换干吗?
8 楼
endlessrain [专家分:10] 发布于 2007-05-23 20:21:00
简单的说,就是精确查找和模糊查找的效果是一样的,都是模糊查找
说明这句话
if c=jingque then
rs.open "select * from product where '"&a&"'='"&b&"' order by "&px&"",conn,1,1
根本没执行
9 楼
endlessrain [专家分:10] 发布于 2007-05-23 20:25:00
已解决,谢谢各位
我来回复