asp中怎么实现两个条件同时模糊查询?求高手解答
我的是一个库存管理的,需要kcname和kcmodel可以单独查询,也可以同时查询,如何实现?我现在的代码如下:<%IfTrim(request("kcname"))<>...
我的是一个库存管理的,需要kcname和kcmodel可以单独查询,也可以同时查询,如何实现?
我现在的代码如下:
<%
If Trim(request("kcname"))<>"" Then
Dim rs,strsql
Set rs=server.createobject("adodb.recordset")
strsql="select * from kczb where kcname like '%"&Trim(request("kcname"))&"%'"
rs.open strsql,db,1
If rs.recordcount<=0 Then
Response.write"没有该种名称的记录"
Else
Do While Not rs.eof
Response.write"<tr bgcolor='#b6b6b6' align='center'>"
Response.write"<td>"&rs("kcno")&"</td>"
Response.write"<td>"&rs("kcname")&"</td>"
Response.write"<td>"&rs("kcmodel")&"</td>"
Response.write"<td>"&rs("unitprice")&"</td>"
Response.write"<td>"&rs("kcnomber")&"</td>"
Response.write"<td>"&rs("totalprice")&"</td>"
Response.write"<td>"&rs("rktime")&"</td>"
Response.write"<td>"&rs("place")&"</td>"
Response.write"<td>"&rs("category")&"</td>"
Response.write"<td>"&rs("remark")&"</td>"
Response.write"</tr>"
rs.movenext
Loop
response.write"</table>"
End If
End If
If trim(request("kcmodel"))<>"" Then
Dim strsql1
Set rs=server.createobject("adodb.recordset")
strsql1="select * from kczb where kcmodel like '%"&Trim(request("kcmodel"))&"%'"
rs.open strsql1,db,1
If rs.recordcount<=0 Then
Response.write"没有该种型号的记录"
Else
Do While Not rs.eof
Response.write"<tr bgcolor='#b6b6b6' align='center'>"
Response.write"<td>"&rs("kcno")&"</td>"
Response.write"<td>"&rs("kcname")&"</td>"
Response.write"<td>"&rs("kcmodel")&"</td>"
Response.write"<td>"&rs("unitprice")&"</td>"
Response.write"<td>"&rs("kcnomber")&"</td>"
Response.write"<td>"&rs("totalprice")&"</td>"
Response.write"<td>"&rs("rktime")&"</td>"
Response.write"<td>"&rs("place")&"</td>"
Response.write"<td>"&rs("category")&"</td>"
Response.write"<td>"&rs("remark")&"</td>"
Response.write"</tr>"
rs.movenext
Loop
response.write"</table>"
End If
End If
%>
此段只能实现单独查询。
两个关键字同时模糊查询,我把sql语句写成select * from kczb where kcname like '%"&Trim(request("kcname"))&"%' and kcmodel like '%"&Trim(request("kcmodel"))&"%'" 实现不了,两个关键字单独查询,sql语句写成select * from kczb where kcname like '%"&Trim(request("kcname"))&"%' or kcmodel like '%"&Trim(request("kcmodel"))&"%'" 也实现不了。 展开
我现在的代码如下:
<%
If Trim(request("kcname"))<>"" Then
Dim rs,strsql
Set rs=server.createobject("adodb.recordset")
strsql="select * from kczb where kcname like '%"&Trim(request("kcname"))&"%'"
rs.open strsql,db,1
If rs.recordcount<=0 Then
Response.write"没有该种名称的记录"
Else
Do While Not rs.eof
Response.write"<tr bgcolor='#b6b6b6' align='center'>"
Response.write"<td>"&rs("kcno")&"</td>"
Response.write"<td>"&rs("kcname")&"</td>"
Response.write"<td>"&rs("kcmodel")&"</td>"
Response.write"<td>"&rs("unitprice")&"</td>"
Response.write"<td>"&rs("kcnomber")&"</td>"
Response.write"<td>"&rs("totalprice")&"</td>"
Response.write"<td>"&rs("rktime")&"</td>"
Response.write"<td>"&rs("place")&"</td>"
Response.write"<td>"&rs("category")&"</td>"
Response.write"<td>"&rs("remark")&"</td>"
Response.write"</tr>"
rs.movenext
Loop
response.write"</table>"
End If
End If
If trim(request("kcmodel"))<>"" Then
Dim strsql1
Set rs=server.createobject("adodb.recordset")
strsql1="select * from kczb where kcmodel like '%"&Trim(request("kcmodel"))&"%'"
rs.open strsql1,db,1
If rs.recordcount<=0 Then
Response.write"没有该种型号的记录"
Else
Do While Not rs.eof
Response.write"<tr bgcolor='#b6b6b6' align='center'>"
Response.write"<td>"&rs("kcno")&"</td>"
Response.write"<td>"&rs("kcname")&"</td>"
Response.write"<td>"&rs("kcmodel")&"</td>"
Response.write"<td>"&rs("unitprice")&"</td>"
Response.write"<td>"&rs("kcnomber")&"</td>"
Response.write"<td>"&rs("totalprice")&"</td>"
Response.write"<td>"&rs("rktime")&"</td>"
Response.write"<td>"&rs("place")&"</td>"
Response.write"<td>"&rs("category")&"</td>"
Response.write"<td>"&rs("remark")&"</td>"
Response.write"</tr>"
rs.movenext
Loop
response.write"</table>"
End If
End If
%>
此段只能实现单独查询。
两个关键字同时模糊查询,我把sql语句写成select * from kczb where kcname like '%"&Trim(request("kcname"))&"%' and kcmodel like '%"&Trim(request("kcmodel"))&"%'" 实现不了,两个关键字单独查询,sql语句写成select * from kczb where kcname like '%"&Trim(request("kcname"))&"%' or kcmodel like '%"&Trim(request("kcmodel"))&"%'" 也实现不了。 展开
展开全部
你把东西改成下面这样看看
<%
Dim rs,strsql
Set rs=server.createobject("adodb.recordset")
If Trim(request("kcname"))<>"" and trim(request("kcmodel"))<>"" Then
strsql = "select * from kczb where kcname like '%"&Trim(request("kcname"))&"%' or kcmodel like '%"&Trim(request("kcmodel"))&"%' "
elseif Trim(request("kcname"))<>"" then
strsql="select * from kczb where kcname like '%"&Trim(request("kcname"))&"%'"
elseif trim(request("kcmodel"))<>"" then
strsql="select * from kczb where kcmodel like '%"&Trim(request("kcmodel"))&"%'"
end if
rs.open strsql,db,1
If rs.recordcount<=0 Then
Response.write"没有该种型号的记录"
Else
Do While Not rs.eof
Response.write"<tr bgcolor='#b6b6b6' align='center'>"
Response.write"<td>"&rs("kcno")&"</td>"
Response.write"<td>"&rs("kcname")&"</td>"
Response.write"<td>"&rs("kcmodel")&"</td>"
Response.write"<td>"&rs("unitprice")&"</td>"
Response.write"<td>"&rs("kcnomber")&"</td>"
Response.write"<td>"&rs("totalprice")&"</td>"
Response.write"<td>"&rs("rktime")&"</td>"
Response.write"<td>"&rs("place")&"</td>"
Response.write"<td>"&rs("category")&"</td>"
Response.write"<td>"&rs("remark")&"</td>"
Response.write"</tr>"
rs.movenext
Loop
response.write"</table>"
End If
Set rs = nothing
%>
<%
Dim rs,strsql
Set rs=server.createobject("adodb.recordset")
If Trim(request("kcname"))<>"" and trim(request("kcmodel"))<>"" Then
strsql = "select * from kczb where kcname like '%"&Trim(request("kcname"))&"%' or kcmodel like '%"&Trim(request("kcmodel"))&"%' "
elseif Trim(request("kcname"))<>"" then
strsql="select * from kczb where kcname like '%"&Trim(request("kcname"))&"%'"
elseif trim(request("kcmodel"))<>"" then
strsql="select * from kczb where kcmodel like '%"&Trim(request("kcmodel"))&"%'"
end if
rs.open strsql,db,1
If rs.recordcount<=0 Then
Response.write"没有该种型号的记录"
Else
Do While Not rs.eof
Response.write"<tr bgcolor='#b6b6b6' align='center'>"
Response.write"<td>"&rs("kcno")&"</td>"
Response.write"<td>"&rs("kcname")&"</td>"
Response.write"<td>"&rs("kcmodel")&"</td>"
Response.write"<td>"&rs("unitprice")&"</td>"
Response.write"<td>"&rs("kcnomber")&"</td>"
Response.write"<td>"&rs("totalprice")&"</td>"
Response.write"<td>"&rs("rktime")&"</td>"
Response.write"<td>"&rs("place")&"</td>"
Response.write"<td>"&rs("category")&"</td>"
Response.write"<td>"&rs("remark")&"</td>"
Response.write"</tr>"
rs.movenext
Loop
response.write"</table>"
End If
Set rs = nothing
%>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
kcname=Trim(request("kcname"))
kcmodel=Trim(request("kcmodel"))
kcname like '%"&kcname&"%' or kcname like '%"&kcmodel&"%'
kcmodel=Trim(request("kcmodel"))
kcname like '%"&kcname&"%' or kcname like '%"&kcmodel&"%'
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询