asp问题求救!(附代码)
<!--# include file="conn.inc"-->
<% @ language=vbs %>
<%
const Head="学生信息查询"
dim conn,strconn
set conn=server.CreateObject("adodb.connection")
strconn="provider=sqloledb;user id=sa;password=;initial catalog=wang;data source=wangxiaolei"
conn.Open strconn
sno=trim(Request.Form("sno"))
sname=trim(Request.Form("sname"))
ssex=trim(Request.Form("ssex"))
sclass=trim(Request.Form("sclass"))
sdept=trim(Request.Form("sdept"))
if sno<>"" and sname<>"" then
condition="学号="&sno&" and 姓名 like '%"&sname&"%'"
end if
dim strsql
strsql="select * from student where "&condition
set string1=conn.Execute(strsql)
set conn=nothing
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gb_2312-80">
<title>学生信息查询</title>
</head>
<body bgcolor="#ffffff">
<h2>
<center>
学生信息查询  <a href="xsxx.html">返回</a>
</center>
</h2>
<table align=left width=800 cellspacing="1" cellspacing="1" border="1" bordercolor="#ffffff" bordercolordark="#b0e0e6" bordercolorlight="#000066" height="44">
<tr bgcolor="#b0e0e6" bordercolor="#000066">
<td align="center" width="160" height="13">
<font style="font-size:14px"><b>学号</b></font></td>
<td align="center" width="160" height="13">
<font style="font-size:14px"><b>姓名</b></font></td>
<td align="center" width="160" height="13">
<font style="font-size:14px"><b>性别</b></font></td>
<td align="center" width="160" height="13">
<font style="font-size:14px"><b>类别</b></font></td>
<td align="center" width="160" height="13">
<font style="font-size:14px"><b>系别</b></font></td>
<% do while not string1.eof%>
<tr>
<td align=center bgcolor="#ffffff" bordercolor="#eeeeff" width="160"
nowrap height="19"><font style="font-size:14px">
<% Response.Write(string1("sno"))%></font></td>
<td align=center bgcolor="#eeeeff" bordercolor="#ffffff" width="160"
nowrap height="19"><font style="font-size:14px">
<% Response.Write(string1("sname"))%></font></td>
<td align=center bgcolor="#ffffff" bordercolor="#eeeeff" width="160"
nowrap height="19"><font style="font-size:14px">
<% Response.Write(string1("ssex"))%></font></td>
<td align=center bgcolor="#eeeeff" bordercolor="#ffffff" width="160"
nowrap height="19"><font style="font-size:14px">
<% Response.Write(string1("sclass"))%></font></td>
<td align=center bgcolor="#ffffff" bordercolor="#eeeeff" width="160"
nowrap height="19"><font style="font-size:14px">
<% Response.Write(string1("sdept"))%></font></td>
</tr>
<%
string1.movenext
loop
%>
</table>
</body>
</html>
大家帮我看看哪里有问题啊?
编译总是出错
去掉condition条件后又可以了
问题点数:0、回复次数:8Top
1 楼fastson()回复于 2003-11-01 11:07:21 得分 0
在
strsql="select * from student where "&condition
后面加上
response.write strsql
response.end
运行一遍,然后把生成的sql语句发上来Top
2 楼chinann(臣煌)回复于 2003-11-01 14:15:52 得分 0
请问楼上,你为什么要加上你写的那个代码呢??
能说明理由吗?谢谢!!Top
3 楼avonqin(不再看连续剧)回复于 2003-11-01 14:28:30 得分 0
仅仅测试Top
4 楼avonqin(不再看连续剧)回复于 2003-11-01 14:31:12 得分 0
condition="学号='"&sno&"' and 姓名 like '%"&sname&"%'"Top
5 楼Tal(Tal)回复于 2003-11-01 14:38:31 得分 0
sno=trim(Request.Form("sno") & "")
sname=trim(Request.Form("sname") & "")
ssex=trim(Request.Form("ssex") & "")
sclass=trim(Request.Form("sclass") & "")
sdept=trim(Request.Form("sdept") & "")
if sno & "" <> "" and sname & "" <> "" then
condition=" and 学号=" & sno & " and 姓名 like '%" & sname & "%'"
end if
dim strsql
strsql="select * from student where 1=1 " & conditionTop
6 楼wangxiaolei456(asp&&java)回复于 2003-11-01 23:44:08 得分 0
学生信息查询 返回
学号 姓名 性别 类别 系别
sno sname ssex sclass sdept
sno sname ssex sclass sdept
sno sname ssex sclass sdept
sno sname ssex sclass sdept
sno sname ssex sclass sdept
上层的楼主,这是按你的改后的结果啊
还是不对啊Top
7 楼wangxiaolei456(asp&&java)回复于 2003-11-02 12:30:20 得分 0
怎么没人回答了?
Top
8 楼Tal(Tal)回复于 2003-11-03 11:33:58 得分 0
<%
sno = trim(Request.Form("sno") & "")
sname = trim(Request.Form("sname") & "")
ssex = trim(Request.Form("ssex") & "")
sclass = trim(Request.Form("sclass") & "")
sdept = trim(Request.Form("sdept") & "")
condition = ""
if sno & "" <> "" then
condition = " and 学号='" & sno & "' "
end if
if sname & "" <> "" then
" and 姓名 like '%" & sname & "%'"
if ssex& "" <> "" then
condition = condition & " and 性别='" & ssex & "' "
end if
if sclass & "" <> "" then
condition = condition & " and 类别='" & sclass & "' "
end if
if sdept & "" <> "" then
condition = condition & " and 系别='" & sdept & "' "
end if
dim strsql
strsql="select * from student where 1=1 " & condition
'你再试试
%>Top




