asp sql 的VB程序问题。按学号、姓名或者院系查找学生信息。
<body><%dims_num,s_nam,s_xis_num=trim(request("s_number"))s_nam=trim(request("s_name"...
<body>
<%
dim s_num,s_nam,s_xi
s_num = trim(request("s_number"))
s_nam = trim(request("s_name"))
s_xi = trim(request("xi"))
ff=0
'判断学号是否为空
if s_num <> "" or s_nam <> "" or s_xi <> "" then
sql="select * from 学生 where 学号 like '%"&s_num&"%' and 姓名 like '%"&s_nam&"%' and 系 like '%"&s_xi&"%' "
ff=1
end if
if ff=0 then
response.write "<script>alert('请输入你查找信息的关键字');history.go(-1)</script>"
end if
if ff=1 then
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,2
end if
%>
<%
if not(rs.eof and rs.bof) then
do while not rs.eof
%>
<%
response.Write "<tr>"
response.Write "<td>"&rs("学号")&"</td>"
response.Write "<td>"&rs("姓名")&"</td>"
response.Write "<td>"&rs("班级")&"</td>"
response.Write "<td>"&rs("年龄")&"</td>"
response.Write "<td>"&rs("性别")&"</td>"
response.Write "<td>"&rs("学院")&"</td>"
response.Write "<td>"&rs("系")&"</td>"
response.Write "<td>"&rs("专业")&"</td>"
response.Write "</tr>"
response.Write "<br>"
rs.movenext
loop
else
response.write "<script>alert('你所查找的学生不存在!请重新输入关键字!');history.go(-1)</script>"
%>
<%
rs.close
set rs = nothing
conn.close
set conn = nothing
end if
%>
</body>
为什么其它的都可以执行但是下面这句话不能执行。提示错误语句是“ 缺少对象: 'rs' ”
response.write "<script>alert('请输入你查找信息的关键字');history.go(-1)</script>" 展开
<%
dim s_num,s_nam,s_xi
s_num = trim(request("s_number"))
s_nam = trim(request("s_name"))
s_xi = trim(request("xi"))
ff=0
'判断学号是否为空
if s_num <> "" or s_nam <> "" or s_xi <> "" then
sql="select * from 学生 where 学号 like '%"&s_num&"%' and 姓名 like '%"&s_nam&"%' and 系 like '%"&s_xi&"%' "
ff=1
end if
if ff=0 then
response.write "<script>alert('请输入你查找信息的关键字');history.go(-1)</script>"
end if
if ff=1 then
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,2
end if
%>
<%
if not(rs.eof and rs.bof) then
do while not rs.eof
%>
<%
response.Write "<tr>"
response.Write "<td>"&rs("学号")&"</td>"
response.Write "<td>"&rs("姓名")&"</td>"
response.Write "<td>"&rs("班级")&"</td>"
response.Write "<td>"&rs("年龄")&"</td>"
response.Write "<td>"&rs("性别")&"</td>"
response.Write "<td>"&rs("学院")&"</td>"
response.Write "<td>"&rs("系")&"</td>"
response.Write "<td>"&rs("专业")&"</td>"
response.Write "</tr>"
response.Write "<br>"
rs.movenext
loop
else
response.write "<script>alert('你所查找的学生不存在!请重新输入关键字!');history.go(-1)</script>"
%>
<%
rs.close
set rs = nothing
conn.close
set conn = nothing
end if
%>
</body>
为什么其它的都可以执行但是下面这句话不能执行。提示错误语句是“ 缺少对象: 'rs' ”
response.write "<script>alert('请输入你查找信息的关键字');history.go(-1)</script>" 展开
1个回答
展开全部
帮你改好了, 并优化了一下结构, 这样看起来就比较清晰了.
<%
if s_num <> "" or s_nam <> "" or s_xi <> "" then
sql="select * from 学生 where 学号 like '%"&s_num&"%' and 姓名 like '%"&s_nam&"%' and 系 like '%"&s_xi&"%' "
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,2
if rs.eof then
response.write "<script>alert('你所查找的学生不存在!请重新输入关键字!');history.go(-1)</script>"
End If
do while not rs.eof
response.Write "<tr>"
response.Write "<td>"&rs("学号")&"</td>"
response.Write "<td>"&rs("姓名")&"</td>"
response.Write "<td>"&rs("班级")&"</td>"
response.Write "<td>"&rs("年龄")&"</td>"
response.Write "<td>"&rs("性别")&"</td>"
response.Write "<td>"&rs("学院")&"</td>"
response.Write "<td>"&rs("系")&"</td>"
response.Write "<td>"&rs("专业")&"</td>"
response.Write "</tr>"
response.Write "<br>"
rs.movenext
loop
rs.close
set rs = nothing
conn.close
set conn = nothing
Else
response.write "<script>alert('请输入你查找信息的关键字');history.go(-1)</script>"
end if
%>
说一下你代码的问题吧
if ff=0 then
response.write "<script>alert('请输入你查找信息的关键字');history.go(-1)</script>"
end if
if ff=1 then
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,2
end if
if not(rs.eof and rs.bof) then ' 这句在ff=0或ff=1时都会执行,但问题是你的rs对象是在ff=1时创建的,当ff=0时,并没有执行创建rs对象的语句,这时调用对象属性就会出错了.
<%
if s_num <> "" or s_nam <> "" or s_xi <> "" then
sql="select * from 学生 where 学号 like '%"&s_num&"%' and 姓名 like '%"&s_nam&"%' and 系 like '%"&s_xi&"%' "
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,2
if rs.eof then
response.write "<script>alert('你所查找的学生不存在!请重新输入关键字!');history.go(-1)</script>"
End If
do while not rs.eof
response.Write "<tr>"
response.Write "<td>"&rs("学号")&"</td>"
response.Write "<td>"&rs("姓名")&"</td>"
response.Write "<td>"&rs("班级")&"</td>"
response.Write "<td>"&rs("年龄")&"</td>"
response.Write "<td>"&rs("性别")&"</td>"
response.Write "<td>"&rs("学院")&"</td>"
response.Write "<td>"&rs("系")&"</td>"
response.Write "<td>"&rs("专业")&"</td>"
response.Write "</tr>"
response.Write "<br>"
rs.movenext
loop
rs.close
set rs = nothing
conn.close
set conn = nothing
Else
response.write "<script>alert('请输入你查找信息的关键字');history.go(-1)</script>"
end if
%>
说一下你代码的问题吧
if ff=0 then
response.write "<script>alert('请输入你查找信息的关键字');history.go(-1)</script>"
end if
if ff=1 then
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,2
end if
if not(rs.eof and rs.bof) then ' 这句在ff=0或ff=1时都会执行,但问题是你的rs对象是在ff=1时创建的,当ff=0时,并没有执行创建rs对象的语句,这时调用对象属性就会出错了.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询