Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts

    paging recordsets

    Am I missing something daft here? The following code:

    Code:
    response.write("mypage: "&mypage&"<br>")
    response.write("numpages: "&numpages&"<br>")
    response.write("numrecs: "&numrecs&"<br>")
    response.write("rs.AbsolutePage: "&rs.AbsolutePage&"<br>")
    
    for i=1 to pagesize
    if not rs.EOF then
    response.write(rs.Fields("SKU_Num")&"<br>")
    rs.movenext
    end if
    next
    
    response.write("mypage: "&mypage&"<br>")
    response.write("numpages: "&numpages&"<br>")
    response.write("numrecs: "&numrecs&"<br>")
    response.write("rs.AbsolutePage: "&rs.AbsolutePage&"<br>")
    produces the following output:

    Code:
    mypage: 1
    numpages: 2
    numrecs: 9
    rs.AbsolutePage: 1
    DL178
    DL114
    DL113
    DL170
    LD147
    mypage: 1
    numpages: 2
    numrecs: 9
    rs.AbsolutePage: 2
    What's with that? Why has my AbsolutePage property just jumped up one? I've listed 5 records out of a possible 9, not moved pages as far as I know... what's going on??


    (Here's some other relevant bits of code...)

    This is the first bit:
    Code:
    dim strSQL, cn, rs, pagesize, numpages, numrecs, mypage
    
    if request.querystring("pg")<>"" then
    mypage=cInt(request.querystring("pg"))
    else
    mypage=1
    end if
    pagesize=5
    Then there's some other boring bits, then there's this bit:

    Code:
    set cn = Server.CreateObject("ADODB.Connection")
    cn.Open ConnectString
    set rs = Server.CreateObject("ADODB.Recordset")
    rs.CursorLocation=3 'clientside
    rs.CursorType=3 'staticrecordset
    rs.PageSize=pagesize
    
    rs.Open strSQL,cn
    
    numpages = rs.PageCount
    numrecs = rs.RecordCount
    If mypage > numpages Then mypage = numpages 
    If mypage < 1 Then mypage = 1
    rs.AbsolutePage = mypage

    ...and then there's the bit at the top.
    Last edited by Spudhead; 02-26-2003 at 06:28 PM.

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Location
    South Africa
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rather try this:

    Code:
    RS.AbsolutePage = mypage
      Do While Not ( RS.Eof Or RS.AbsolutePage <> mypage)
        response.write(rs.Fields("SKU_Num")&"<br>")
        rs.movenext
      loop
    It works for me

  • #3
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Thinking about this, it's obvious why it's screwing up. At the end of any loop, the cursor is always going to be on the next page; because the last thing that the loop does is move it to the next record.

    I was having problems with this because I was writing out "previous" and "next" buttons based on the rs.AbsolutePage value. Change it so that the "if" statements are evaluated against the "mypage" value instead, and everything works


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •