此分页技术读取字段名称与记录都是采用循环语句的方法
1.定义要用到的常量与变量
****************************************************
<%
const MaxPerPage=10 '每页显示的记录数为10
dim sql '定义查询数据库的SQL语句所使用的变量
dim rs
dim totalPut
dim CurrentPage '定义当前页的变量
dim TotalPages 定义循环用到的2个变量
dim i,j
%>
****************************************************
2.连接数据库并显示分页导航
****************************************************
<%
conn = "DBQ=" + server.mappath("mydb.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
sql = "SELECT * FROM mytable"
set rs=server.createobject("adodb.recordset")
rs.open SQL,conn,1,1
rs.MoveFirst
rs.pagesize=MaxPerPage
howmanyfields=rs.Fields.Count-1 '记录集字段属性rs.Fields是从0开始的,为0-rs.Fields.Count-1
If trim(Request("Page"))<>"" then
CurrentPage= CLng(request("Page"))
If CurrentPage> rs.PageCount then
CurrentPage = rs.PageCount
End If
Else
CurrentPage= 1
End If
if rs.eof then
response.write "
ERROR!
"
else
totalPut=rs.recordcount
if CurrentPage<>1 then
if (currentPage-1)*MaxPerPage
rs.move(currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
end if
end if
dim n,k
if (totalPut mod MaxPerPage)=0 then
n= totalPut \ MaxPerPage
else
n= totalPut \ MaxPerPage + 1
end if%>
第<%=currentpage%>页 共<%=n%>页 共<%=rs.recordcount%>条 纪录
<% k=currentPage
if k<>1 then
response.write "["+"首页] "
response.write "["+"上一页] "
else
Response.Write "[首页] [上一页]"
end if
if k<>n then
response.write "["+"下一页] "
response.write "["+"尾页] "
else
Response.Write "[下一页] [尾页]"
end if
%>
****************************************************
3.显示数据
****************************************************
<%
for i= 0 to howmanyfields%>
<%=rs(i).name%> |
<%
next
i=0
do while not rs.eof and i
<%for j=0 to howmanyfields%>
<%=rs(j)%> |
<%next%>
<%
i=i+1
rs.movenext
loop
%>
****************************************************
4.关闭数据库连接
****************************************************
<%
end if
rs.close
set rs=nothing
%>
****************************************************
阅读(1840) | 评论(0) | 转发(0) |