Print Page | Close Window

getting a specific number of records

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=6035
Printed Date: 31 March 2026 at 3:19am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: getting a specific number of records
Posted By: portaloo
Subject: getting a specific number of records
Date Posted: 29 September 2003 at 3:00am
What I'm trying to do is get a specific number of records from a large db.

I know i can use getrows and other methods which will speed up access but what I am wondering is if it is possible to select a number of records.

ie on page 1 select records from 1 to 25, on page 2 select records 26 to 50 etc etc until the last record is displayed.

My thinking is this, if I've got 700 records why waste the time and resources getting the last page by retrieving the first 675 records when they aren't even going to be used. I think that by doing something like this I can speed things up more.

Another question - am I just being silly about this, will there be any time/resource savings at all?

Cheers

portaloo


-------------
T.P.L.K.



Replies:
Posted By: b_bonnett
Date Posted: 29 September 2003 at 3:15am

Take a look over http://www.devguru.com/Technologies/ado/quickref/recordset.html - http://www.devguru.com/Technologies/ado/quickref/recordset.h tml . The parts you are interested in are PageSize, AbsolutePage, PageCount and LockType.

There is also a good tutorial at http://www.asp101.com/samples/viewasp.asp?file=db%5Fpaging%2Easp - http://www.asp101.com/samples/viewasp.asp?file=db%5Fpaging%2 Easp .

Hope this helps,
Blair



-------------
Webmaster, http://www.planegallery.net/ - The Plane Gallery
Greetings From Christchurch


Posted By: portaloo
Date Posted: 29 September 2003 at 4:31am
yo Blair right back at ya from chch too


Posted By: 3BEPb
Date Posted: 30 September 2003 at 9:20pm

AFAIK this is paging thru recordset. Let me write simple one for you:

<%
Const intPageSize = 10 'this is number of records on one page
Dim intCurrentPage, strQ
Dim intTotalPages, I

If Request("Page") = "" Then
   intCurrentPage = 1
Else
   intCurrentPage = CInt(Request("Page"))
End If

dim objConn, RS, AppDatabase, SQL, totRec, RS2, totRec2, Author, Blurb, Title, Story, sLad

Set objConn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
RS.Cursorlocation = adUseClient
RS.CursorType = adOpenStatic
RS.PageSize = intPageSize
AppDatabase="Driver={SQL Server};DSN=;Server=112.112.112.112;UID=userID;PWD=password"
objConn.Open AppDatabase
Set RS.ActiveConnection=objConn

RS.Open "SELECT * FROM your_table"

If Not(RS.EOF) Then RS.AbsolutePage = intCurrentPage

intTotalPages = RS.PageCount
totRec=RS.RecordCount
If totRec = 0 Then
response.write "No records available"
Else

I=0
do until I = RS.PageSize
 I=I+1

response.write RS("Something")

 RS.MoveNext
 If RS.EOF Then Exit do
loop
RS.Close
objConn.Close
End If
If intCurrentPage > 1 Then %><a href="<%= Request.ServerVariables("SCRIPT_NAME")%>?Page=<%= (intCurrentPage-1)%>">
                   <b>back</b></a> |<%End If%>Page <%=intCurrentPage%> 
                    out of <%=intTotalPages%> | <%If totRec <> 0 Then
    If intCurrentPage <> intTotalPages Then%>| <a href="<%= Request.ServerVariables("SCRIPT_NAME")%>?Page=<%= (intCurrentPage+1)%>><b>forward</b></a& gt; 
                   <%
  End If
End If
%>



Posted By: Gullanian
Date Posted: 01 October 2003 at 12:58am

You can do:

SELECT TOP int *



Posted By: b_bonnett
Date Posted: 01 October 2003 at 4:32am

One thing I'd add to the code 3BEPb gave you is to check the number of pages, then make sure the user is not trying to view a page out of the limits, then set the page we are viewing within the recordset.

Blair



-------------
Webmaster, http://www.planegallery.net/ - The Plane Gallery
Greetings From Christchurch



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net