如何分页显示数据库查询结果?

<%
if Request.QueryString("PageNumber").count > 0 then

' 指定页号的参数PageNumber.如果指定页号,则以指定页号为依据.

PageNumber = Request.QueryString("PageNumber")(1)
else
PageNumber = 1

' 如没指定页号,缺省为1.
end if

RecordNumberPerPage = 10

' 每页显示10条记录.

 set ARecordSet = Server.CreateObject("ADODB.RecordSet")
ARecordSet.open "select * from contact1",AConnection,1
' 执行查询,注意Open语句中指定的第三个参数.

ARecordSet.PageSize = RecordNumberPerPage

' 指定每页记录条数.
ARecordSet.AbsolutePage = PageNumber

' 指定当前页号.

Response.Write "
每页有"&ARecordSet.PageSize&"条记录"
Response.Write "
共有"&ARecordSet.PageCount&""
Response.Write "
这是第"&PageNumber&""

Response.Write "

"
' 以表格形式显示查询结果.

Response.Write "
"
For FieldNo = 0 to ARecordSet.Fields.count - 1
Response.Write ""
Next
Response.Write ""
' 显示字段名.

RecordCounter = 0
Do while not ARecordSet.eof
RecordCounter = RecordCounter + 1
'
显示查询.

if RecordCounter > RecordNumberPerPage then

' 如果要显示的记录数大于每页记录数目,则停止显示.
Exit do
end if

 Response.Write "

"
For FieldNo = 0 to ARecordSet.Fields.count - 1
Response.Write ""
Next
Response.Write ""

' 显示一条记录.

 ARecordSet.MoveNext
Loop
'
转向下一条记录.

Response.Write "

"&ARecordSet( FieldNo ).Name&"
"&ARecordSet( FieldNo )&"
"

if PageNumber > 1 then

' 如果不是第一页,则提示上一页.
Response.Write "

[上一页]"

[1] [2]  下一页

你可能感兴趣的:(如何分页显示数据库查询结果?)