How To Page Through a Recordset from ASP

Article translations Article translations
Article ID: 202125 - View products that this article applies to.
This article was previously published under Q202125
Expand all | Collapse all

SUMMARY

This article describes how to use the PageSize, PageCount, and AbsolutePage properties of an ADO recordset and what cursor types must be used to get Recordset Paging to work.

MORE INFORMATION

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>
				

When using Recordset Paging against SQL Server, you can use a server side cursor. However, you must use either a Static or a Keyset cursor type. Otherwise, no data will be returned. If you use a client side cursor, all cursor types will work, but only a static cursor is returned.

When using Recordset Paging against Microsoft Access, you must use a client side cursor. Any cursor type will work, but again only a static cursor is returned. A server side cursor will not return any data.

When using Recordset Paging against Oracle, you can use a server side cursor, but if you do, you must use a Static or Keyset cursor type. Otherwise, no data will be returned. If you use a client side cursor, all cursor types will work, but only a keyset cursor is returned.

Properties

Article ID: 202125 - Last Review: July 15, 2004 - Revision: 1.4
APPLIES TO
  • Microsoft ActiveX Data Objects 2.0
  • Microsoft ActiveX Data Objects 2.1 Service Pack 2
  • Microsoft ActiveX Data Objects 2.5
  • Microsoft ActiveX Data Objects 2.6
  • Microsoft ActiveX Data Objects 2.7
  • Microsoft Active Server Pages 4.0
Keywords: 
kbcodesnippet kbdatabase kbhowto kbmdacnosweep KB202125
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com