+ -
当前位置:首页 → 问答吧 → 关于ASP当中模糊查找数据库内容

关于ASP当中模糊查找数据库内容

时间:2011-12-03

来源:互联网

我在想要查找一个数据库表中的数据,当用户的各项输入没有填写的时候则显示所有数据组,如果有要求则显示包含用户输入的内容的数据组
但是我在不填男或女的时候无法查找出来数据,除非我填了男或者女。我是对用户输入空进行了判断的。
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<table border=1 id='result' >
<body>
<%
dim sql
dim rID,rName,rSex,rDept,rGrade0,rGrade1

//用户录入信息
rrID=Request.Form("rID")
rrName=Request.Form("rName")
rrSex=Request.Form("rSex")
rrDept=Request.Form("rDept")
rrGrade0=Request.Form("rGrade0")
rrGrade1=Request.Form("rGrade1")


'dt = Replace(dt,"/", "-")
If rGrade0<>""and rGrade1<>""Then
  string1="and rGrade between '"&rGrade0&"' and '"&rGrade1&"'"
  
else
  string1=""
end if 

If rSex<>""Then
  string2="and rSex = '"&rrSex&"'"
  
else
  string2=""
end if 

'and bDate between #"&bbDate0&"# and #"&bbDate1&"#
dim rs
//该查询已经通过
set rs=Session("s_DBConn").Execute("SELECT * FROM Reader WHERE rID like '%"&rrID&"%' and rName like '%"&rrName&"%'and rSex = '"&rrSex&"'and rDept like '%"&rrDept&"%' "&string2&string1)
while NOT rs.EOF

//注意在库数量需要改变<td>"&rs("bExistCnt")&"</td>这里暂时这么存着,把Bid多打了一次应付输出
//
' Response.Write("<tr><td>"&rs("bID")&"</td><td>"&rs("bID")&"</td><td>"&rs("bName")&"</td><td>"&rs("bCnt")&"</td><td>"&rs("bPub")&"</td><td>"&rs("bDate")&"</td><td>"&rs("bAuthor")&"</td><td>"&rs("bMem")&"</td></tr><br>")
Response.Write("<tr><td>"&rs("rID")&"</td>")
Response.Write("<td>"&rs("rName")&"</td>")
Response.Write("<td>"&rs("rSex")&"</td>")
Response.Write("<td>"&rs("rDept")&"</td>")
Response.Write("<td>"&rs("rGrade")&"</td></tr><br>")
rs.MoveNext()
wend

if rs.EOF then Response.Write("<table border=1 id='result' ></table>")

rs.Close()
set rs=nothing
%>
</table>
</body>
</html>

作者: shaoxin0827   发布时间: 2011-12-03

If rGrade0<>""and rGrade1<>""Then
string1="and rGrade between '"&rGrade0&"' and '"&rGrade1&"'"

else
string1=""
end if

If rGrade0<>""and rGrade1<>""Then
  string1="and rGrade between "&rGrade0&" and "&rGrade1&""
   
else
  string1=""
end if  



作者: enjoy_gw   发布时间: 2011-12-05

热门下载

更多