如何分頁顯示資料庫查詢結果?

來源:互聯網
上載者:User

<%
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 "<br>每頁有"&ARecordSet.PageSize&"條記錄"
Response.Write "<br>共有"&ARecordSet.PageCount&"頁"
Response.Write "<br>這是第"&PageNumber&"頁"

Response.Write "<Table border=1>"
' 以表格形式顯示查詢結果.

Response.Write "<tr>"
For FieldNo = 0 to ARecordSet.Fields.count - 1
Response.Write "<td>"&ARecordSet( FieldNo ).Name&"</td>"
Next
Response.Write "</tr>"
' 顯示欄位名.

RecordCounter = 0
Do while not ARecordSet.eof
RecordCounter = RecordCounter + 1
' 顯示查詢.

if RecordCounter > RecordNumberPerPage then

' 如果要顯示的記錄數大於每頁記錄數目,則停止顯示.
Exit do
end if

 Response.Write "<tr>"
For FieldNo = 0 to ARecordSet.Fields.count - 1
Response.Write "<td>"&ARecordSet( FieldNo )&"</td>"
Next
Response.Write "</tr>"

' 顯示一條記錄.

 ARecordSet.MoveNext
Loop
' 轉向下一條記錄.

Response.Write "</Table>"

if PageNumber > 1 then

' 如果不是第一頁,則提示上一頁.
Response.Write "<p><A href = chunfeng.asp?PageNumber="&(PageNumber-1)&">[上一頁]</a>"

[1] [2]  下一頁

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.