本人做毕业设计,打算做一个搜索,调用数据库里的数据。
自己制作了一个简单的数据库和页面
下面是我的代码
<%
dim conn
dim rs
dim sql
set conn=server.createobject("adodb.connection")
conn.open "Driver={SQL Server};server=(local);uid=sa;pwd=sa;database=text;"
set rs=server.createobject("adodb.recordset")
dim QueryString
QueryString=request.form("QueryString")
sql="select * from sq where"
if QueryString<>"" and request.form("radiobutton")="歌手"then
sql=sql &"Sname like '%"&Sname&"%'order by id asc"
flag=1
end if
if QueryString<>"" and request.form("radiobutton")="歌曲"then
sql=sql &"Mname like '%"&Mname&"%'order by id asc"
flag=1
end if
if QueryString<>"" and request.form("radiobutton")="专辑"then
sql=sql &"group like '%"&group&"%' order by id asc"
flag=1
end if
if flag=0 then
sql="select * from sq order by id asc"
end if
rs.Open sql,conn,1,1
%>
<html>
<head>
<title>显示结果</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.style4 { font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.style3 {font-size: small}
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="20%"> </td>
<td width="58%"><div align="center"> <img src="PIC/index_clip_image002.gif" width="310" height="141"> </div></td>
<td width="22%"> </td>
</tr>
</table></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="index1.asp">
<table width="100%" height="125" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table width="83%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="62"><table width="57%" height="39" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="32"> </td>
<td width="438"><table width="436" height="30" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="80%" height="10"><input name="QueryString" type="text" id="QueryString" size="50">
</td>
<td width="3%"> </td>
<td width="17%"><input type="submit" name="Submit" value="搜索"></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="radio" name="radiobutton" value="歌手">
<span class="style4">歌手</span>
<input type="radio" name="radiobutton" value="歌曲">
<span class="style4">歌曲</span>
<input type="radio" name="radiobutton" value="歌词">
<span class="style4">歌词</span>
<input type="radio" name="radiobutton" value="专辑">
<span class="style4">专辑</span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</form></td>
</tr>
</table>
<table width="42%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>统计查询共有
<% =rs.RecordCount %>
条纪录</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
</table>
<table width="50%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center">歌手</div></td>
<td><div align="center">歌曲</div></td>
<td><div align="center">专辑</div></td>
</tr>
</table>
<table width="50%" border="0" align="center" cellpadding="0" cellspacing="0">
<%
do while not rs.eof
%>
<tr>
<td width="25%"><div align="center"><%=rs("Sname")%></div></td>
<td width="25%"><div align="center"><%=rs("Mname")%></div></td>
<td width="25%"><div align="center"><%=rs("group")%></div></td>
</tr>
<%
rs.movenext
loop
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
</table>
<p> </p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><a href="#" class="style4">设它为首页</a><span class="style3"> | </span><a href="#" target="_self" class="style4">添加它为着页</a></div></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="11"><div align="center" class="style4"><a href="#">关于我们</a> | <a href="mailto:freedomsq@163.com">联络我们</a> | <a href="#">搜索风云榜</a> | <a href="#">企业推广</a></div></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center" class="style4">2007年1月11日 freesq </div></td>
</tr>
</table>
</body>
</html>
这段代码是做搜索的
dim conn
dim rs
dim sql
set conn=server.createobject("adodb.connection")
conn.open "Driver={SQL Server};server=(local);uid=sa;pwd=sa;database=text;"
set rs=server.createobject("adodb.recordset")
dim QueryString
QueryString=request.form("QueryString")
sql="select * from sq where"
if QueryString<>"" and request.form("radiobutton")="歌手"then
sql=sql &"Sname like '%"&Sname&"%'order by id asc"
flag=1
end if
if QueryString<>"" and request.form("radiobutton")="歌曲"then
sql=sql &"Mname like '%"&Mname&"%'order by id asc"
flag=1
end if
if QueryString<>"" and request.form("radiobutton")="专辑"then
sql=sql &"group like '%"&group&"%' order by id asc"
flag=1
end if
if flag=0 then
sql="select * from sq order by id asc"
end if
rs.Open sql,conn,1,1
%>
设计界面
文本框名是QueryString
(<input name="QueryString" type="text" id="QueryString" value="请输入关键字" size="50">)
单选框名是radiobutton
(<input type="radio" name="radiobutton" value="radiobutton">)
数据库表和界面我已经上传到附件上好。。