如何分页显示数据库查询结果?
- 技术交流
- 2024-10-01 10:23:01
<%
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 ""&ARecordSet( FieldNo ).Name&" "
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 ""&ARecordSet( FieldNo )&" "
Next
Response.Write "
ARecordSet.MoveNext
Loop
' 转向下一条记录.
Response.Write "
if PageNumber > 1 then
' 如果不是第一页,则提示上一页.
Response.Write "上一页]"
[1] [2] 下一页
如何分页显示数据库查询结果?由讯客互联技术交流栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“如何分页显示数据库查询结果?”