ASP基础实例教程之五个小时学会Asp连接access添加,删除,修改二
点击次数:44 次 发布日期:2008-12-01 17:05:42 作者:源代码网
|
现在来学把数据库的信息输出来 下面先建立一个主文件index.asp 代码如下 CODE:
<!--#include file="conn.asp"--> <% exec="select * from aa order by id desc " set rs=server.createobject("adodb.recordset") rs.open exec,conn,1,1 %> <table width="628" height="24" border="1" align="center" cellpadding="1" cellspacing="0"> <% if rs.eof and rs.bof then response.write("暂时没有文章") else do while not rs.eof %> <tr> <td width="66" height="22" ><%=rs("id")%></td> <td width="66" ><%=rs("name")%></td> <td width="66" ><%=rs("content")%></td> <td width="273" ><%=rs("xhtime")%></td> <td width="53" ><%=rs("title")%></td> <td><a href="modify.asp?id=<%=rs("id")%>" target="_self">编辑</a></td> <td width="32" ><a href="del.asp?id=<%=rs("id")%>">删除</a></td> </tr> <% rs.movenext loop end if %> </table> <% rs.close set rs=nothing conn.close set conn=nothing %> <td><a href="add.asp">添加</a></td> [Copy to clipboard] 代码解释: (1)<% exec="select * from aa order by id desc " set rs=server.createobject("adodb.recordset") rs.open exec,conn,1,1 %> 上面的代码是创建一个recordset对象。。该对象是用来打开数据库中的表的。。也就是打开aa exec="select * from aa order by id desc " 这句的意思是查找表aa中所有信息并倒序排列 信息. *号表示aa中所有的信息 order by id 就是aa中id字段 desc 是倒序的意思 rs.open exec,conn,1,1 这句话的意思是用recordset对象来打开conn中的表 (2) <% if rs.eof and rs.bof then response.write("暂时没有文章") else do while not rs.eof %> 上面是if语句。。if else语句是相当重要的。。 希望一些初学者要认真的研究一下if else语句。。不可心急。基础才是硬道理 rs.eof 的意思是aa表中的最后一条记录 那么rs.bof就是第一条记录 整个语句用中文翻译就是 当aa表中的最后和最前一条信息没有的时候。。就输出暂时没有文章 或则就循环到eof最后一条信息。。 (3)<tr> <td width="66" height="22" ><%=rs("id")%></td> <td width="66" ><%=rs("name")%></td> <td width="66" ><%=rs("content")%></td> <td width="273" ><%=rs("xhtime")%></td> <td width="53" ><%=rs("title")%></td> <td><a href="modify.asp?id=<%=rs("id")%>" target="_self">编辑</a></td> <td width="32" ><a href="del.asp?id=<%=rs("id")%>">删除</a></td> </tr> 上面的代码比较容易理解。。<%=rs("id")%>这个用法是输出数据库字段id.. <a href="modify.asp?id=<%=rs("id")%>" target="_self">编辑</a>这段很重要。。 我来解释一下。。在ie窗口点 编辑 的时候。。页面会跳转到modify.asp的文件里的id 并进行相应的处理。。这里很难解释清楚。。在接下来的例子中再慢慢解说 (4) <% rs.movenext loop end if %> 这句是循环结束的语句 rs.movenext 这句是游标向下指的意思 (5) <% rs.close set rs=nothing conn.close set conn=nothing %> 这句是关闭数据库的语句 用完数据库后要记得关闭数据库。。以免占用资源 养成随手关门的好习惯 就学到这里。。好好消化上面的代码。。心急吃不了热豆腐。。 一步一个脚印最塌实 源文件下 源代码网供稿. |
