小孩精力不集中:ASP怎样显示数据库里的内容

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 11:45:13
我刚接触ASP.昨天老师讲课的时候给了一道练习题.
感觉相对ASP编程高手来说比较简单.
练习题目是拿 一个班级里的学生来做例子的。

现在的代码实现了.

添加班级.添加重复班级提示.返回重新添加(连接).

数据库是AC的.
现在. 我想实现.如果在我添加过班级后可以显示. 我原来全部添加过的班级.并且是从后添加的开始显示的..

大家可以参考一下代码..

这个是提交页面.我想实现在提交过后可以显示全部添加班级内容.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>添加班级</title>
</head>

<body>
<form action="add_class_to_mdb.asp" method="post">
<table width="490" border="1" align="center">
<tr>
<td width="117" height="55" nowrap>班级名称:</td>
<td width="357"><input name="classname" type="text" id="classname" size="50" maxlength="50"></td>
</tr>
<tr>
<td colspan="2"><table width="200" border="0" align="center">
<tr>
<td><input type=submit value="提交"></td>
<td><input type=reset value="重置"></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>

这个是提交过后的显示内容文件

<%
my_bjmc=ltrim(trim(request.form("classname")))
if len(my_bjmc)=0 then
response.write "<center><font size=10><strong>班级名称不得为空!<strong></font></center>"
response.end
end if
%>

<!--#include file="conn.asp"-->

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>add_class_to_mdb.asp</title>
</head>
<body>

<%
set rs=server.CreateObject("adodb.recordset") ''''''建立recordset对象
sqlstr="select count(*) as mycount from class where rtrim(class_name)='"&my_bjmc&"'"
'response.write sqlstr
'response.end

rs.open sqlstr,conn,1,3
if rs("mycount")>0 then
rs.close
set rs=nothing
response.write "<center><font size=10><strong>班级名称重复!<strong></font></center>"%>
<!--#include file="closedata.asp"-->
<meta http-equiv='Refresh' content='2; URL=add_class.asp'>
<% response.end
end if

response.write rs("mycount")&"<br>"
rs.close
set rs=nothing

set rs=server.CreateObject("adodb.recordset") ''''''建立recordset对象
sqlstr="select * from class" '''''test_table为数据库中的一个数据表,即你要显示的数据所存放的数据表
rs.open sqlstr,conn,1,3 '''''表示打开数据库的方式
rs.addnew ''''''新增加一条记录
rs("class_name")=my_bjmc
rs.update
rs.close
set rs=nothing
response.write "<center><font size=10><strong>班级"&my_bjmc&"添加成功!<strong></font></center>"
%>
<table width="200" border="1" align="center">
<tr>
<td><div align="center"><a href="add_class.asp" target="_parent">再次添加新班级</a></div></td>
</tr>
</table>
</body>
<!--#include file="closedata.asp"-->
</html>

set rs=server.CreateObject("adodb.recordset") ''''''建立recordset对象
sqlstr="select * from class" '''''test_table为数据库中的一个数据表,即你要显示的数据所存放的数据表
rs.open sqlstr,conn,1,3 '''''表示打开数据库的方式
rs.addnew ''''''新增加一条记录
rs("class_name")=my_bjmc
rs.update
rs.close
set rs=nothing
response.write "<center><font size=10><strong>班级"&my_bjmc&"添加成功!<strong></font></center>"
%>

这后面可以添加
<%
response.rediract("ShowAll.asp")
%>

ShowAll.asp内容主要是
<%
set rs=server.CreateObject("adodb.recordset") ''''''建立recordset对象
sqlstr="select * from class" '''''test_table为数据库中的一个数据表,即你要显示的数据所存放的数据表
rs.open sqlstr,conn,1,3
Do while not Rs.eof
response.write Rs("Class")&"<br>"
Rs.movenext
Loop
Rs.close
Set Rs=nothing

数据库是AC的.
现在. 我想实现.如果在我添加过班级后可以显示. 我原来全部添加过的班级.并且是从后添加的开始显示的..

首先的的表中需要添加一个自动编号字段或者加入时间字段都可以,这里以自动编号字段 ID 为例:
添加成功后在本页面或定向其它页面都可以,代码如下:
rs.open "select * from 表名 order by ID desc",conn,1,1
do while not rs.eof
response.write rs("班级字段名")&"<br>"
rs.movenext
loop
rs.close
conn.close
set conn=nothing

我问个问题,一定要SET rs吗?SET其他字段行不行?