asp代码实现多条件的查询
我用以下代码编写,查询提交后没有反应。请问该怎么修改?或有什么更好的代码?<%Dimconn,strConn,DbPathDbPath=Server.Mappath("A...
我用以下代码编写,查询提交后没有反应。请问该怎么修改?或有什么更好的代码?
<%
Dim conn,strConn,DbPath
DbPath=Server.Mappath("A.mdb")
Set conn=Server.CreateObject("ADODB.Connection")
strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DbPath
conn.Open strConn
dim rs,strsql,a,b
a=request.Form("text")
b=request.Form("button")
set rs=server.CreateObject("ADODB.Recordset")
if b="" then
strsql="select * From Book"
else
if b=1 then
strsql="select * From Book where strBook='" & a & "'"
else
strsql="select * From Book where strAuthor='" & a & "'"
end if
end if
rs.open strsql,conn,1,3
%>
<title>查询借阅</title>
<h2 align="center">图书借阅查询</h2>
<form name="form1"method="POST"action="">
<p><tr>请选择查询条件:<tr>按书名查询<lable><input name="searchBy" type="radio" value="strBook" checked="checked" />
</lable>按作者查询<lable><input type="radio" name="searchBy" value="strAuthor" />
</lable><br>输 入 关 键 字:<lable><input type="text"name="txtName"></lable>
<lable><input type="submit"name="submit"value="提交"></lable>
</p>
</form>
</style>
<p align="center"> </p>
<table border="1" width="100%" >
<tr bgcolor="#E0E0E0">
<th>书名</th><th>作者</th><th>单价</th><th>出版社</th><th>库存</th><th>借阅</th>
</tr>
<%
Do While Not rs.Eof
%>
<tr>
<td><%=rs("book")%></td>
<td><%=rs("author")%></td>
<td><%=rs("price")%></td>
<td><%=rs("publish")%></td>
<td><%=rs("num")%></td>
<td align="center"><a href="borrowadd.asp?BookID=<%=rs("BookID")%>">借阅</a></td>
</tr>
<%
rs.MoveNext
Loop
%>
</table>
<p> </p>
<%
rs.close
set rs=nothing
conn.close
set conn=nothing
%></td>
</tr>
</table> 展开
<%
Dim conn,strConn,DbPath
DbPath=Server.Mappath("A.mdb")
Set conn=Server.CreateObject("ADODB.Connection")
strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DbPath
conn.Open strConn
dim rs,strsql,a,b
a=request.Form("text")
b=request.Form("button")
set rs=server.CreateObject("ADODB.Recordset")
if b="" then
strsql="select * From Book"
else
if b=1 then
strsql="select * From Book where strBook='" & a & "'"
else
strsql="select * From Book where strAuthor='" & a & "'"
end if
end if
rs.open strsql,conn,1,3
%>
<title>查询借阅</title>
<h2 align="center">图书借阅查询</h2>
<form name="form1"method="POST"action="">
<p><tr>请选择查询条件:<tr>按书名查询<lable><input name="searchBy" type="radio" value="strBook" checked="checked" />
</lable>按作者查询<lable><input type="radio" name="searchBy" value="strAuthor" />
</lable><br>输 入 关 键 字:<lable><input type="text"name="txtName"></lable>
<lable><input type="submit"name="submit"value="提交"></lable>
</p>
</form>
</style>
<p align="center"> </p>
<table border="1" width="100%" >
<tr bgcolor="#E0E0E0">
<th>书名</th><th>作者</th><th>单价</th><th>出版社</th><th>库存</th><th>借阅</th>
</tr>
<%
Do While Not rs.Eof
%>
<tr>
<td><%=rs("book")%></td>
<td><%=rs("author")%></td>
<td><%=rs("price")%></td>
<td><%=rs("publish")%></td>
<td><%=rs("num")%></td>
<td align="center"><a href="borrowadd.asp?BookID=<%=rs("BookID")%>">借阅</a></td>
</tr>
<%
rs.MoveNext
Loop
%>
</table>
<p> </p>
<%
rs.close
set rs=nothing
conn.close
set conn=nothing
%></td>
</tr>
</table> 展开
2个回答
展开全部
a=request.Form("text")
b=request.Form("button")
改成
a=request.Form("txtName")
b=request.Form("searchBy")
if b=1 then
strsql="select * From Book where strBook='" & a & "'"
else
strsql="select * From Book where strAuthor='" & a & "'"
end if
改成
if b="searchBy" then
strsql="select * From Book where strBook='" & a & "'"
else
strsql="select * From Book where strAuthor='" & a & "'"
end if
b=request.Form("button")
改成
a=request.Form("txtName")
b=request.Form("searchBy")
if b=1 then
strsql="select * From Book where strBook='" & a & "'"
else
strsql="select * From Book where strAuthor='" & a & "'"
end if
改成
if b="searchBy" then
strsql="select * From Book where strBook='" & a & "'"
else
strsql="select * From Book where strAuthor='" & a & "'"
end if
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
A.mdb 数据库Book 表中有记录吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询