凹丫丫网络社区's Archiver

Amm 发表于 2008-5-15 16:22

显示数据库记录

<STRONG><FONT size=4><FONT color=#cc0000><FONT face=新宋体>原理:将数据库中的记录一一显示到客户端浏览器,依次读出数据库中的每一条记录<WBR><WBR><BR><WBR><FONT style="LINE-HEIGHT: 1.3em"><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em">如果是从头到尾:用循环并判断指针是否到末使用: not rs.eof</FONT><WBR></FONT></FONT></FONT></FONT><WBR><WBR><BR></STRONG><B><WBR><FONT style="LINE-HEIGHT: 1.3em" face=新宋体><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" color=#cc0000>如果是从尾到头:用循环并判断指针是否到开始使用:not rs.bof</FONT><WBR></FONT><WBR></B><WBR><BR><B><WBR><FONT style="LINE-HEIGHT: 1.3em" face=新宋体><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" color=#cc0000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--#include file=conn.asp--&gt;&nbsp;&nbsp;&nbsp;&nbsp;(包含conn.asp用来打开bbs\db1\目录下的user.mdb数据库)</FONT><WBR></FONT><WBR></B><WBR><BR><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" face=新宋体 color=#cc0000><B><WBR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;%</B><WBR></FONT><WBR><BR><B><WBR><FONT style="LINE-HEIGHT: 1.3em" face=新宋体><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" color=#cc0000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set rs=server.CreateObject("adodb.recordset")&nbsp;&nbsp;(建立recordset对象)</FONT><WBR></FONT><WBR></B><WBR><BR><B><WBR><FONT style="LINE-HEIGHT: 1.3em" face=新宋体><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" color=#cc0000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sqlstr="select * from message"&nbsp;&nbsp;----&gt;(message为数据库中的一个数据,即你要显示的数据所存放的数据表)</FONT><WBR></FONT><WBR></B><WBR><BR><B><WBR><FONT style="LINE-HEIGHT: 1.3em" face=新宋体><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" color=#cc0000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.open sqlstr,conn,1,3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ----&gt;(表示打开数据库的方式)</FONT><WBR></FONT><WBR></B><WBR><BR><B><WBR><FONT style="LINE-HEIGHT: 1.3em" face=新宋体><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" color=#cc0000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.movefirst&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;----&gt;(将指针移到第一条记录)</FONT><WBR></FONT><WBR></B><WBR><BR><B><WBR><FONT style="LINE-HEIGHT: 1.3em" face=新宋体><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" color=#cc0000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while not rs.eof&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;----&gt;(判断指针是否到末尾)</FONT><WBR></FONT><WBR></B><WBR><BR><B><WBR><FONT style="LINE-HEIGHT: 1.3em" face=新宋体><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" color=#cc0000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; response.write(rs("name"))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;----&gt;(显示数据表message中的name字段)</FONT><WBR></FONT><WBR></B><WBR><BR><B><WBR><FONT style="LINE-HEIGHT: 1.3em" face=新宋体><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" color=#cc0000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.movenext&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ----&gt;(将指针移动到下一条记录)</FONT><WBR></FONT><WBR></B><WBR><BR><B><WBR><FONT style="LINE-HEIGHT: 1.3em" face=新宋体><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" color=#cc0000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wend&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;----&gt;(循环结束)</FONT><WBR></FONT><WBR></B><WBR><BR><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" face=新宋体 color=#cc0000><B><WBR>------------------------------------------------------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </B><WBR></FONT><WBR><BR><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" face=新宋体 color=#cc0000><B><WBR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.close</B><WBR></FONT><WBR><BR><B><WBR><FONT style="LINE-HEIGHT: 1.3em" face=新宋体><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" color=#cc0000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.close&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;这几句是用来关闭数据库</FONT><WBR></FONT><WBR></B><WBR><BR><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" face=新宋体 color=#cc0000><B><WBR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set rs=nothing</B><WBR></FONT><WBR><BR><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" face=新宋体 color=#cc0000><B><WBR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set c</B><WBR></FONT><WBR><BR><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" face=新宋体 color=#cc0000><B><WBR>-------------------------------------------------------</B><WBR></FONT><WBR><BR><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" face=新宋体 color=#cc0000><B><WBR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%&gt;</B><WBR></FONT><WBR><BR><B><WBR><FONT style="FONT-SIZE: medium; LINE-HEIGHT: 1.3em" face=新宋体 color=#cc0000>其中response对象是服务器向客户端浏览器发送的信息</FONT><WBR></B><WBR><BR><IMG id=paperPicArea1 style="DISPLAY: none; POSITION: relative" src="http://imgcache.qq.com/ac/qzone_v4/b.gif">

页: [1]

Powered by Discuz! Archiver 7.0.0  © 2001-2007 Comsenz Inc.