| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 424 人关注过本帖
标题:大家帮帮我
只看楼主 加入收藏
freedomsq
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-1-24
收藏
 问题点数:0 回复次数:0 
大家帮帮我

本人做毕业设计,打算做一个搜索,调用数据库里的数据。
自己制作了一个简单的数据库和页面
下面是我的代码

<%
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%">&nbsp;</td>
<td width="58%"><div align="center"> <img src="PIC/index_clip_image002.gif" width="310" height="141"> </div></td>
<td width="22%">&nbsp;</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">&nbsp;</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%">&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</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
%>


可是运行结果前面3个IF语句总是不执行,直接执行最后一个if flag=0,请问哪位高手帮偶看下啊

设计界面
文本框名是QueryString
(<input name="QueryString" type="text" id="QueryString" value="请输入关键字" size="50">)
单选框名是radiobutton
(<input type="radio" name="radiobutton" value="radiobutton">)

数据库表和界面我已经上传到附件上好。。
图片附件: 游客没有浏览图片的权限,请 登录注册

图片附件: 游客没有浏览图片的权限,请 登录注册

搜索更多相关主题的帖子: 数据库 sql database server local 
2007-01-24 12:10
快速回复:大家帮帮我
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031049 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved