|
 |
asp_web_howto thread: Displaying Large Recordsets
Message #1 by "Rick Lull" <ricklull@h...> on Fri, 15 Mar 2002 21:56:33
|
|
I have a custom search feature that builds a complex SQL statement based
on criteria the user enters - which can sometimes return (relatively)
large recordsets of 200 or more rows. I only want to display 15 per page.
I can get the first 15 to display, but how do I move through the remaining
100+ 15 at a time? Do I have to resubmit a query each time? I would
greatly appreciate suggestions. Thanks.
Message #2 by "Drew, Ron" <RDrew@B...> on Fri, 15 Mar 2002 18:00:56 -0500
|
|
Example.... http://www.4guysfromrolla.com/webtech/121298-1.shtml
<%@ LANGUAGE=3D"VBSCRIPT" %>
<% Option Explicit %>
<!--#include virtual=3D"/ADOVBS.inc"-->
<%
'Set how many records per page we want
Const NumPerPage =3D 10
'Retrieve what page we're currently on
Dim CurPage
If Request.QueryString("CurPage") =3D "" then
CurPage =3D 1 'We're on the first page
Else
CurPage =3D Request.QueryString("CurPage")
End If
Dim conn
Set conn =3D Server.CreateObject("ADODB.Connection")
conn.Open "DSN=3DMyDB"
'Explicitly Create a recordset object
Dim rs
Set rs =3D Server.CreateObject("ADODB.Recordset")
'Set the cursor location property
rs.CursorLocation =3D adUseClient
'Set the cache size =3D to the # of records/page
rs.CacheSize =3D NumPerPage
'Open our recordset
Dim strSQL
strSQL =3D "SELECT Name,Salary FROM Employee ORDER BY Name"
rs.Open strSQL, Conn
rs.MoveFirst
rs.PageSize =3D NumPerPage
'Get the max number of pages
Dim TotalPages
TotalPages =3D rs.PageCount
'Set the absolute page
rs.AbsolutePage =3D CurPage
'Counting variable for our recordset
Dim count
%>
<HTML>
<BODY>
<B>Name - Salary</B><BR>
<%
'Set Count equal to zero
Count =3D 0
Do While Not rs.EOF And Count < rs.PageSize
Response.Write(rs("Name") & " - " & rs("Salary") & "<BR>")
Count =3D Count + 1
rs.MoveNext
Loop
'Print out the current page # / total pages
Response.Write("Page " & CurPage & " of " & TotalPages & "<P>")
'Display Next / Prev buttons
if CurPage > 1 then
'We are not at the beginning, show the prev button
Response.Write("<INPUT TYPE=3DBUTTON VALUE=3DPREV
ONCLICK=3D""document.location.href=3D'thisfile.asp?curpage=3D" & curpage
- 1 &
"';"">")
End If
if CInt(CurPage) <> CInt(TotalPages) then
'We are not at the end, show a next button
Response.Write("<INPUT TYPE=3DBUTTON VALUE=3DNEXT
ONCLICK=3D""document.location.href=3D'thisfile.asp?curpage=3D" & curpage
+ 1 &
"';"">")
End If
%>
</BODY>
</HTML>
-----Original Message-----
From: Rick Lull [mailto:ricklull@h...]
Sent: Friday, March 15, 2002 4:57 PM
To: ASP Web HowTo
Subject: [asp_web_howto] Displaying Large Recordsets
I have a custom search feature that builds a complex SQL statement based
on criteria the user enters - which can sometimes return (relatively)
large recordsets of 200 or more rows. I only want to display 15 per
page.
I can get the first 15 to display, but how do I move through the
remaining
100+ 15 at a time? Do I have to resubmit a query each time? I would
greatly appreciate suggestions. Thanks.
Message #3 by "Ken Schaefer" <ken@a...> on Sun, 17 Mar 2002 17:22:46 +1100
|
|
www.adopenstatic.com/experiments/recordsetpaging.asp
has code for three different types of recordset paging. The "easiest", but
slowest is using the in built ADO methods.
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Rick Lull" <ricklull@h...>
Subject: [asp_web_howto] Displaying Large Recordsets
: I have a custom search feature that builds a complex SQL statement based
: on criteria the user enters - which can sometimes return (relatively)
: large recordsets of 200 or more rows. I only want to display 15 per page.
: I can get the first 15 to display, but how do I move through the remaining
: 100+ 15 at a time? Do I have to resubmit a query each time? I would
: greatly appreciate suggestions. Thanks.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
 |