Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Recordset paging
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Recordset paging

 Post Reply Post Reply
Author
Mattblack View Drop Down
Groupie
Groupie
Avatar

Joined: 21 January 2003
Location: United Kingdom
Status: Offline
Points: 139
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mattblack Quote  Post ReplyReply Direct Link To This Post Topic: Recordset paging
    Posted: 02 December 2004 at 5:47pm
boo, back again!
 
Im struggling to use paging for a recordset, never done it before so i went to w3schools and following it all to the letter - no joy!
 
open the recordset
rs.pagesize=5
 
this shows ALL records not just the first page. Do I have to set the page its on? How do i do it anyhow for page 2?
 
Also, rs.pagecount writes "-1" when it should be about 4 pages.
 
Totally confused, ive followed it to the letter.  Have also tried with different locktypes.
 
Pleeeeeeeeeeeeease help
 
Back to Top
rx7tt View Drop Down
Groupie
Groupie


Joined: 25 October 2004
Location: United States
Status: Offline
Points: 53
Post Options Post Options   Thanks (0) Thanks(0)   Quote rx7tt Quote  Post ReplyReply Direct Link To This Post Posted: 02 December 2004 at 9:05pm

I will trim down some code and post it shortly.

Back to Top
rx7tt View Drop Down
Groupie
Groupie


Joined: 25 October 2004
Location: United States
Status: Offline
Points: 53
Post Options Post Options   Thanks (0) Thanks(0)   Quote rx7tt Quote  Post ReplyReply Direct Link To This Post Posted: 02 December 2004 at 9:56pm

The code is pretty bland but I wanter to make sure it was understandable. Please let me know if you have any questions.

Thanks
 
<%
Set sqlConn = SERVER.CREATEOBJECT("ADODB.CONNECTION")
SET RS = SERVER.CREATEOBJECT("ADODB.RECORDSET")

' This will tell the recordset what page your on
Page = Request.QueryString("page")' Declare page number
If Page = "" Then
  iPageCurrent = CInt(1)'If there is no page then page is 1
Else
  iPageCurrent = CInt(Page)
End If

'Set the cursor type property of the record set to dynamic so we can naviagate through the record set
rs.CursorType = 1

'----------------------------------------------------------- ------
' Open your connection and recordset here
'----------------------------------------------------------- ------

'This will tell the recordset how many records to return
iPageSize = 10

'Get the total number of records in the recordset
iTotalRecords = RS.RecordCount ' Total # of records

'Define max number of records
RS.PageSize = iPageSize

'Get the total number of page in the recordset
iPageCount = RS.PageCount ' Total # of pages

'Move to the current page in the recordset
RS.AbsolutePage = iPageCurrent

'Counter to keep track of the number of records displayed
iRecordsShown = 0

'Loop thru records until Page Size is reached
Do While iRecordsShown < iPageSize AND Not RS.EOF

  '----------------------------------------------------------- ------
  ' Output you recorset
  ' eg Response.Write RS("Record1")
  '----------------------------------------------------------- ------

  'increment counter
  RS.MoveNext
  iRecordsShown = iRecordsShown + 1
Loop

If iPageCurrent > 1 Then
  Response.Write "<a href=""test.asp?page=" & iPageCurrent - 1 & """>Previous " & iPageSize & "</a>" & vbCrLf
End If

'Display a next link if needed
If iPageCount <> iPageCurrent Then
  Response.Write "<a href=""test.asp?page=" & iPageCurrent + 1 & """>Next " & iPageSize & "</a>" & vbCrLf
End If

'Clean up
RS.Close
Set RS = Nothing
sqlConn.Close
Set sqlConn = Nothing
%>

Back to Top
Mattblack View Drop Down
Groupie
Groupie
Avatar

Joined: 21 January 2003
Location: United Kingdom
Status: Offline
Points: 139
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mattblack Quote  Post ReplyReply Direct Link To This Post Posted: 03 December 2004 at 7:41am
excellent, ive got it working.
 
I missed out the cursor location with the type.
 
Thanks mate
Back to Top
rx7tt View Drop Down
Groupie
Groupie


Joined: 25 October 2004
Location: United States
Status: Offline
Points: 53
Post Options Post Options   Thanks (0) Thanks(0)   Quote rx7tt Quote  Post ReplyReply Direct Link To This Post Posted: 05 December 2004 at 8:27pm

Glad to help Smile

Mobile Gear.biz-Ringtones, games, videos, links and more...
Wireless Forums
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.