有关分页显示数据库的记录

大家好,我有一个问题想请教你们,就是有关怎么分页显示数据库的记录。
问题是这样的我有一个access数据库,我想将数据库中的每条记录用一页来显示,我的代码基本上完成,但是我还是实现不了,并且,我现在都不知道怎么去改动,希望你能帮助我,谢谢

1<html>
2<head>
3<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
4<title>分页显示</title>
5</head>
6<body>
7<p>   

dim curpage,i,nowpage
curpage=request.querystring("currentpage")
if curpage="" then nowpage=1 else nowpage=cInt(curpage)
set adoconn=server.createobject("adodb.connection")
adoconn.open"dsn=ql;database=db"
set adors=server.createobject("adodb.recordset")
adors.activeconnection=adoconn
adors.cursortype=adopenstatic
adors.pagesize=1
adors.open"select * from b1"
adors.absolutepage=nowpage
I=0
response.write("<table border="1" width="100%">")
response.write("<tr><td>id</td>")
response.write("<td>xm</td>")
response.write("<td>jg</td>")
response.write("<td>xb</td>")
response.write("<td>nl</td></tr>")
do while(not adors.eof)and(I&lt; adors.pagesize)
I=I+1
response.write("<tr><td>"&amp;adors("id") &amp;"</td>")
response.write("<td>"&amp; adors("xm")&amp;"</td>")
response.write("<td>"&amp; adors("jg") &amp;"</td>")
response.write("<td>"&amp; adors("xb")&amp;"</td>")
response.write("<td>"&amp; adors("nl") &amp;"</td></tr>")
adors.movenext
loop
response.write("</table><br/>")
for I=1 to adors.pagecount
if I=nowpage then
response.write (I &amp;"")
else
response.write("<a href='3.asp?currentpage="&amp;I&amp;"'>"&amp;I&amp;"</a>")
end if
next
adors.close
set adors=nothing
adoconn.close
set adoconn=nothing

1<p>
2</p></p></body>
3</html>

每次调试,提示错误是

Microsoft VBScript 编译器错误 错误 '800a03f6'

缺少 'End'

/iisHelp/common/500-100.asp,行242

ADODB.Recordset 错误 '800a0cb3'

对象或提供者不能执行所需的操作。

/ttm/1/3.asp,行20

---------------------------------------------------------------

adors.activeconnection=adoconn
adors.cursortype=adopenstatic
adors.pagesize=1
adors.open"select * from b1"

改成
adors.open"select * from b1" ,adoconn,1,1
---------------------------------------------------------------

你的这一句if curpage="" then nowpage=1 else nowpage=cInt(curpage)应该再加上一个end if吧
给你一个我经常编写的分页显示的程序吧

1<table width="98%">
2<tbody>
3<tr>
4<td colspan="2" height="9" valign="top"><img alt="" border="0" height="5" src="" width="1"/></td>
5</tr>   

pagenum = cint(request.querystring("page"))
if pagenum = 0 then
pagenum = 1
end if
pagesize = 15
set adocon = server.createobject("adodb.connection")
adocon.open "driver={microsoft access driver (*.mdb)};dbq=" &amp; server.mappath("houtai/news.mdb")
set rs = server.CreateObject("adodb.recordset")
rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic
rs.LockType = adLockOptimistic
sqlstr = "select * from news where sort = " &amp; 1 &amp; " order by date desc"
rs.open sqlstr,adocon,,,adcmdtext
if rs.recordcount &lt;&gt; 0 then
rs.cachesize = pagesize
rs.pagesize = pagesize
rs.absolutepage = pagenum
total = rs.pagecount
for record = 1 to pagesize
if rs.eof then
exit for
else

 1<tr>
 2<td align="middle" width="15"><b>·</b></td>
 3<td class="v15">
 4<a =="" ```","","toolbar='no,status=no,menubar=no,resizable=no,height=450,width=665,scrollbars=yes")' href="#" onclick='javascript:window.open("houtai/details.asp?id=```' rs("id")="">```
 5=rs("title")
 6```</a>   
 7 <font color="#8080c0">```
 8=datevalue(rs("date"))
 9```</font><br/></td>
10</tr>   

end if
rs.movenext
next
response.write "<tr><td align="right" class="v15" colspan="2"><br/><br/>"
if pagenum &gt;= 1 then
response.write "<a class="font1" href='news.asp?page=" &amp; 1 &amp; "'>第一页</a>"
end if
response.write " "
if pagenum &gt; 1 then
response.write "<a class="font1" href='news.asp?page=" &amp; pagenum - 1 &amp; "'>上一页</a>"
end if
response.write " "
if pagenum &lt; total then
response.write "<a class="font1" href='news.asp?page=" &amp; pagenum + 1 &amp; "'>下一页</a>"
end if
response.write " "
if pagenum &lt;= total then
response.write "<a class="font1" href='news.asp?page=" &amp; total &amp; "'>最后页</a>"
end if
response.write " 共有" &amp; rs.recordcount &amp; "条记录,第" &amp; pagenum &amp; "/" &amp; total &amp; "页,15条/页    </td></tr>"
end if
rs.close:set rs = nothing
adocon.close:set adocon = nothing

1<tr>
2<td align="right" colspan="2"> </td>
3</tr>
4</tbody>
5</table>

---------------------------------------------------------------

下面的代码可以满足你!

 1   
 2Set rs1 =Server.CreateObject("ADODB.Recordset")   
 3sql1="select * from class"   
 4rs1.open sql1,conn,1,1   
 5  
 6rs1.PageSize=1   
 7if request.queryString("id")<>"" then   
 8if rs1.recordcount<>0 then   
 9rs1.AbsolutePage=CLng(request.queryString("id"))   
10end if   
11end if   
 1<html>
 2<head>
 3<meta content="zh-cn" http-equiv="Content-Language"/>
 4<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
 5<meta content="Microsoft FrontPage 4.0" name="GENERATOR"/>
 6<meta content="FrontPage.Editor.Document" name="ProgId"/>
 7<link href="css" rel="StyleSheet" type="text/css"/>
 8<title>资料分类管理</title>
 9</head>
10<body>   

if not rs1.eof then

 1<table border="1" bordercolor="#00FFCC" cellpadding="0" cellspacing="0" width="100%">
 2<tr>
 3<td bgcolor="#00FFCC" width="100%">
 4<p align="center">资料分类管理</p></td>
 5</tr>
 6<tr>
 7<td width="100%">
 8<table border="0" cellpadding="0" cellspacing="1" width="100%">
 9<tr>
10<td align="center" width="50%">分类名</td>
11<td align="center" width="25%">修改</td>
12<td align="center" width="25%">删除</td>
13</tr>   

for i=1 to rs1.pagesize

1<tr>
2<td align="center" width="50%">```
3=rs1("class")
4```</td>
5<td align="center" width="25%"><a =rs1("id")="" ```="" href="datafl_edit.asp?id=```">修改</a></td>
6<td align="center" width="25%"><a =rs1("id")="" ```="" href="datafl_del.asp?id=```">删除</a></td>
7</tr>   

rs1.movenext
if rs1.eof then
exit for
end if
next

 1<tr>
 2<td align="center" colspan="3" width="100%">
 3<table border="0" bordercolor="#000000" width="100%">
 4<tr>
 5<td width="50%">```
 6for i=1 to rs1.PageCount
 7```<a =i="" ```="" href="datafl.asp?id=```">```
 8=i
 9``` </a>```
10next
11```</td>   

if request.queryString("id")="" then
oldid="1"
else
oldid=request.queryString("id")
end if

1<td width="50%">当前第```
2=oldid
3```页 ¦ 总计:```
4=rs1.PageCount
5```页 ¦ 总记录:```
6=rs1.recordcount
7```条</td>
8</tr>
9</table>   

rs1.close
set rs1=nothing

1</td>
2</tr>
3</table>
4</td>
5</tr>
6</table>   
7\-----------------------------------------------------------------------   
8人在江湖,人不由已!我喜欢程序员这职业!</body></html>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus