回 帖 发 新 帖 刷新版面

主题:" ' 的问题

<%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个回复)

沙发

单引号只是针对字符串而言的。所以这样写是错误的,字段不需要单引号。
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

板凳

不是说 双引号 里面的 双引号要变成单引号的吗?

3 楼

还有这语句好象控制不了

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 楼

我与碰到过类似问题,ASP对SQL的操作中,对字段加上引号不会报错,但会出现一些奇奇怪怪的现象

5 楼

你是怎么解决的啊

6 楼

Str = Replace(Str, "'","''")

7 楼

什么意思?

替换干吗?

8 楼

简单的说,就是精确查找和模糊查找的效果是一样的,都是模糊查找

说明这句话
 if c=jingque then
          rs.open "select * from product where '"&a&"'='"&b&"' order by "&px&"",conn,1,1
根本没执行

9 楼

已解决,谢谢各位

我来回复

您尚未登录,请登录后再回复。点此登录或注册