大家帮忙看看这段sql的查询语句是哪出了问题

来源:百度知道 编辑:UC知道 时间:2024/05/23 13:35:32
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("../mdb/book.mdb")
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
%>

<%
name=request.form("name")
atype=request.form("type")
publishing=request.form("publishing")

if name <>"" then
Sql= Sql & "and name like ’%"& name &"%’"
end if
if atype <>"" then
Sql= Sql & "and type like ’%"& atype &"%’"
end if
if publishing <>"" then
Sql= Sql & "and publishing like ’%"& publishing &"%’"
end if

%>

<table width="900" border="2" cellspacing="0" cellpadding="

<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("../mdb/book.mdb")
set rs=server.createobject("adodb.recordset")
'rs.open sql,conn,1,1 这句我注释掉,不应该先在这里执行的,因为这时候你的sql还没赋值
%>

<%
name=request.form("name")
atype=request.form("type")
publishing=request.form("publishing")

sql="" '我加上了这句
if name <>"" then
Sql= Sql & "and name like ’%"& name &"%’"
end if
if atype <>"" then
Sql= Sql & "and type like ’%"& atype &"%’"
end if
if publishing <>"" then
Sql= Sql & "and publishing like ’%"& publishing &"%’"
end if

response.write sql '把这个sql查询串打印出来看看是否是你想要的结果

rs.open sql,conn,1