Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 8th, 2004, 07:26 AM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Paging Recordsets

I am relativley new to ASP and have hit a slight problem and seeking help.
Based on a combination of code from Wrox's Professional ASP 3 and ASP 3 Programmers Reference books I have constructed a page for listing records from a database that pages through the records to show 5 records on each page and at the bottom of the page is previous and next buttons with text showing page X of Y.

All works well until I reach the last page when the number of records is less than the pageSize variable (eg the number records remaining is 3 and pageSize is set to 5) when I get an exception error.

I have constructed this using a pageSize variable and a counter variable in a Do While loop to iterate through the records. But it seems what's missing is some way of telling the loop that it has reached an end of file. The error is generated when it reaches the first vairable in the recordset when there are less than 5 records left to view. I have included some of my code to help illustrate this.

My question(s) is am I using the right method for dispalying these records? and is there some way I can include an EOF ? This code works well if the pageSize variable is set to 1 (ie display one record on each page)

initially varCount is set to 1 and pageSize is set to 5.

Do while varCount <= rsData.pageSize
Response.Write("<tr align=""center"" bordercolor=""#ffffff"">")
    if session("PersonID") <> "" then
    response.Write("<td><a class=""links1"" href=""browse.asp?Action=Edit&Item=" &

rsData("CaseID") & """>" &_
    rsData("CaseID") & "</a></td>")
    else
    Response.Write("<td>" & rsData("CaseID") & "</td>")
    end if
Response.Write(" <td class=""bodycopy1"">" & rsData("Title") & "</td>" &_
            " <td class=""bodycopy1"">" & rsData("ProjectManager") & "</td>" &_
            " <td class=""bodycopy1"">" & rsData("BuildingName") & "</td>" &_
            " <td class=""bodycopy1"">" &

FormatDatetime(rsData("ListingDate"),2) & "</td>" &_
            " <td class=""bodycopy1"">" & rsData("ItemStatus") & "</td></tr>")

    varCount = varCount + 1
    rsData.MoveNext
    loop

 
Old April 8th, 2004, 08:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can put the EOF checking code as given below. Put an if condition next to your DO WHILE and close that before LOOP statement.
That should work.

Do while varCount <= rsData.pageSize
   IF NOT rsData.EOF THEN
        ...
        ...
        ...
        rsData.MoveNext
    END IF
loop

Cheers!

-Vijay G
 
Old April 8th, 2004, 08:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Actually you can add that condition to your DO WHILE itself. No need of IF there. The problem with the IF condition as given in my previous post is, even after reaching the EOF, untill VARCOUNT becomes > than PAGESIZE, it would loop through unnecessarily. As in your case the PAGESIZE is 5, one would not see any big effect. When it is changed to a bigger value, it could affect the performance. To avoid that you may check for NOT EOF in DO WHILE itself.

Do while varCount <= rsData.pageSize and NOT rsData.EOF
        ...
        ...
        ...
        rsData.MoveNext
loop

Cheers!

-Vijay G
 
Old April 13th, 2004, 05:01 AM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just tried your second suggestion and works beautifully. Thanks for your help

regards
Sparky






Similar Threads
Thread Thread Starter Forum Replies Last Post
DB recordset paging using ajax paging? kumiko Classic ASP Basics 0 May 26th, 2008 10:23 AM
Paging recordsets gilgalbiblewheel Classic ASP Databases 2 January 5th, 2005 05:26 AM
Paging Through Recordsets tuffour Classic ASP Databases 1 August 10th, 2004 01:57 PM
Paging through Recordsets - Please Help buckster Classic ASP Databases 4 May 7th, 2004 07:57 AM
Recordsets bph Access VBA 17 February 17th, 2004 03:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.