我这个代码是实现通讯录的模糊查询!现在的问题是能实现模糊查询,也能返回结果!就是一打开主页面,数据库里的记录就会全部显示出来!!我不想让他显示出来,只想实现模糊查询,需要如何更改代码?敬请高手指教!谢谢
<!--#include file="../Connections/telephonebook.asp" -->
<%
Dim tongxunlu
Dim tongxunlu_numRows
Set telephonebook=Server.CreateObject("ADODB.Connection")
telephonebook.Open "DSN=tongxunlu;Datebase=telephonebook"
Set tongxunlu = Server.CreateObject("ADODB.Recordset")
msgErr=""
username=trim(request("UserName")+"")
strsql="select * from telephonebook where 1=1 "
if len(username)>=1 then
strsql=strsql+" and name like '%" +username +"%' "
end if
tongxunlu_numRows = 0
tongxunlu.Open strsql,telephonebook
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>农行通讯录</title>
<style type="text/css">
<!--
.style1 {
font-size: 36px;
color: #0000FF;
font-weight: bold;
}
body {
background-color: #99FFFF;
}
.style6 {
font-size: 16px;
color: #0000FF;
}
.style7 {
font-size: 12px;
color: #0000FF;
}
-->
</style>
</head>
<body>
<p align="center"> <span class="style1">濮阳农行通讯录</span></p>
<form name="form1" method="post" action="">
<table width="700" border="0">
<tr>
<td width="399"><div align="center"><span class="style6">请输入您要查询的关键字(支持模糊查询)</span></div></td>
<td width="291"><input name="UserName" type="text" value="<%=UserName%>">
<input type="submit" name="Submit" value="提交"></td></tr>
</table>
<p> </p>
<table width="700" border="1">
<tr>
<td width="78"><div align="center"><span class="style7">姓 名</span></div></td>
<td width="37"><div align="center"><span class="style7">性别</span></div></td>
<td width="191"><div align="center"><span class="style7">单 位</span></div></td>
<td width="74"><div align="center"><span class="style7">职 务</span></div></td>
<td width="80"><div align="center"><span class="style7">办公电话</span></div></td>
<td width="114"><div align="center"><span class="style7">手机</span></div></td>
<td width="80"><div align="center"><span class="style7">家庭电话</span></div></td>
</tr>
<%do while not tongxunlu.EOF%>
<tr>
<td><%=(tongxunlu("name"))%></td>
<td><%=(tongxunlu("sex"))%></td>
<td><%=(tongxunlu("danwei"))%></td>
<td><%=(tongxunlu("zhiwu"))%></td>
<td><%=(tongxunlu("phone_work"))%></td>
<td><%=(tongxunlu("phone_hand"))%></td>
<td><%=(tongxunlu("phone_home"))%></td>
</tr>
<%tongxunlu.MoveNext
loop
tongxunlu.close
telephonebook.close%>
</table>
</form>
</body>
</html>