打印

[ASP在线教程] 通过asp与access数据库建立连接(附源码)(3)

通过asp与access数据库建立连接(附源码)(3)

三)显示/查看数据库记录:
<%
set dbconnection=server.createobject("adodb.connection")
dbpath = server.mappath("customer.mdb")
dbconnection.open "driver={microsoft access driver (*.mdb)};dbq=" & dbpath
建立与数据库的连接,与上同。
sql="select * from 客户 order by 时间 desc"
set customerlist=dbconnection.execute(sql)
%>
建立sql查询语句,表示从"客户"表中查询所有记录,order by 时间 desc表示"按时间降序排序,"这样最后添加的信息再最上面显示。下面一句执行sql查询并将结果返回给recordset对象customerlist。
<html>
<body>
<font size="5"><center>数据库记录</center></font>
<center>
<table border=1>
<tr>
<td>编号</td>
<td>公司名称</td>
<td>联络人姓名</td>
<td>所在城市</td>
<td>电话号码</td>
</tr>
<% do while not customerlist.eof %>
检测记录是否到了最后一条。eof表示end of file。
<tr>
<td><% =customerlist("客户编号") %></td>
<td><% =customerlist("公司名称") %></td>
<td><% =customerlist("联络人姓名") %></td>
<td><% =customerlist("所在城市") %></td>
<td><% =customerlist("电话号码") %></td>
</tr>
<% =customerlist("客户编号") %>可以说是response.write方法的简写。将"客户编号"字段内的数据写入td标签间。
<% customerlist.movenext
loop
%>
如果还没有到最后一条则指针移动到下一条。用do while ... loop循环逐一取得所有的记录。

</table>
</center>

<center>
<input type="button" onclick="javascript:location.href='add.htm'" value="添加数据">
</center>
</body>
</html>
缺陷:仅仅实现了最基本的功能。先不说其它功能,仅就数据的添加和查看功能来看,比较完美的还应该加入“分页功能”。否则数据大到一定程度显示全部数据基本上是不可能的。
本期至此全部完毕。






TOP

返回顶部
AYBlue

Processed in 0.045612 second(s), 7 queries.

当前时区 GMT+8, 现在时间是 2009-1-8 13:07 京ICP备06054220号

清除 Cookies - 联系我们 - 163K.com - Archiver - WAP