...

View Full Version : paging recordsets



Spudhead
02-26-2003, 06:21 PM
Am I missing something daft here? The following 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:



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:


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:



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.

david7777
02-27-2003, 08:38 AM
Rather try this:



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:)

Spudhead
02-27-2003, 06:10 PM
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 :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum