HOWTO: ADO 2 Recordset Paging, What Cursor Type To UseID: Q202125
|
This article describes how to use the PageSize, PageCount, and AbsolutePage properties of an ADO 2 recordset and what cursor types must be used to get Recordset Paging to work.
This sample code demonstrates using Recordset Paging against the Adventure Works Access database.
The code Assumes the system DSN named AdvWorks is pointing to the Adventure Works Access 97 database.
<%@ EnableSessionState=False Language=VBScript %>
<%
set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=AdvWorks"
set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3 ' adUseClient
rs.Open "Select * from Employees", conn
rs.PageSize = 2
intPageCount = rs.PageCount
Select Case Request("Action")
case "<<"
intpage = 1
case "<"
intpage = Request("intpage")-1
if intpage < 1 then intpage = 1
case ">"
intpage = Request("intpage")+1
if intpage > intPageCount then intpage = IntPageCount
Case ">>"
intpage = intPageCount
case else
intpage = 1
end select
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>ASP & ADO Paging</TITLE>
</HEAD>
<BODY bgColor=White text=Black>
<%
rs.AbsolutePage = intPage
For intRecord = 1 To rs.PageSize
Response.Write "Record number: " & intRecord & " "
Response.Write rs.Fields("FirstName") & " "
Response.Write rs.Fields("LastName") & "<br>"
rs.MoveNext
If rs.EOF Then Exit For
Next
rs.Close
set rs = Nothing
conn.Close
set conn = nothing
%>
<form name="MovePage" action="default.asp" method="post">
<input type="hidden" name="intpage" value="<%=intpage%>">
<input type="submit" name="action" value="<<">
<input type="submit" name="action" value="<">
<input type="submit" name="action" value=">">
<input type="submit" name="action" value=">>">
Page: <%=Intpage & " of " & intpagecount%>
</form>
</BODY>
</HTML>
Additional query words:
Keywords : kbADO kbASP kbInternet kbGrpASP kbInetDev
Version : WINDOWS:2.0; winnt:
Platform : WINDOWS winnt
Issue type : kbhowto
Last Reviewed: May 25, 1999