Library code snippets
Paginate a recordset
Although SQL Server an Access support the TOP keyword to limit
the amount of records returned, you cannot specify a starting value; making it
unsuitable for use when paginating a recordset (ie displaying records over multiple
pages, as in a web directory). Fortunately, ADO provides an alternative:
'create a recordset object
Set rItems = Server.CreateObject("ADODB.Recordset")
'set the cursor location and type
rItems.CursorLocation = 3' adUseClient
rItems.CursorType = 3 'adOpenStatic
'number of rows to cache at a time. Should be set to the same as PageSize
rItems.CacheSize = 10
'number of items to display per 'page'
rItems.PageSize = 10
'execute the SQL query, and keep the recordset open
'you cannot use the Execute statement for this.
rItems.Open sSQL, cConn
'check if empty
If rItems.EOF Then
'no rows
Else
'set current page
rItems.AbsolutePage = Request.QueryString("page")
'get the total number of records
nItemCount = rItems.RecordCount
'get the number of pages
nPageCount = rItems.PageCount
'loop through an display the items in the recordset
Do While Not rItems.EOF and nItem < rItems.PageSize
'do something
rItems.MoveNext 'move to the next
record
nItem=nItem+1 'increment count
Loop
End If
'close the recordset
rItems.Close
'and destroy the object...
Set rItems = Nothing
Related articles
Related discussion
-
Calling a function from ASP code
by dunk00 (3 replies)
-
GridView HyperLinkField Problem
by Paul2 (0 replies)
-
looking for help on asp
by cladironbeard (2 replies)
-
simple vb to c#, help please
by lksath (1 replies)
-
Binary Studio | software development outsourcing Ukraine
by Hexfinity (2 replies)
Related podcasts
-
Scott Guthrie
Scott catches up with Scott Guthrie in an interview covering Ajax, Asp 2.0, extender controls, CSS adapters and more.
Events coming up
-
Aug
27
Model-View-Presenter (MVC) in ASP.NET
San Francisco, United States
Model-View-Presenter (MVC) in ASP.NET Presenter Clayton Peddy, Terrace Software, Inc. Details TBD
Dear James
Kindly give the example
Error Type:
ADODB.Recordset (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/country/result.asp, line 80
Hi James Crowley
Thanks for your sample code, but if you provide with sample ASP page that will call this sample code. May be you can provide asp page that will display navigation buttons like first page, next page, previous page etc., and explain the code, how this will function.
Expecting reply.
Thanks in advance..
Regards,
Pargunan P
This thread is for discussions of Paginate a recordset.