Help with PageCount Property when Paging thru recordset

Results 1 to 6 of 6

Thread: Help with PageCount Property when Paging thru recordset

  1. #1
    Join Date
    Dec 1969
    Posts
    13

    Default Help with PageCount Property when Paging thru recordset

    Beginner having problems attempting to page through a database. I&#039m testing on both IIS4.0 and using Peer Web Server 3.0 Version 4. on my NT Workstation. It&#039s an Access database. I based my code from two sites: the ASP 101 paging sample and the 4GuysFromRolla.com. After that not working, I downloaded one of the code samples and can&#039t get that to work, either. I&#039m always stuck after I open up the recordset and try to get the PageCount. (I know that the recordset opens because I put a bunch of displays in. If I hard code a number for the page count the script works fine.)<BR><BR>Here&#039s the problem line:<BR>iPageCount = objPagingRS.PageCount <BR><BR>The statement above will give me "-1" . Which, naturally, results in an error when I use that value to set the AbsolutePage paramater. If you have any ideas on what this problem is I&#039d sure appreciate it! The full code is below:<BR><BR>Dim CONN_STRING<BR>Dim CONN_USER<BR>Dim CONN_PASS<BR><BR>CONN_STRING = "DBQ=" & Server.MapPath("database.mdb") & ";"<BR>CONN_STRING = CONN_STRING & "DefaultDir=" & Server.MapPath("./") & ";"<BR>CONN_STRING = CONN_STRING & "Driver={Microsoft Access Driver (*.mdb)};DriverId=25;"<BR>CONN_STRING = CONN_STRING & "FIL=MS Access;ImplicitCommitSync=Yes;"<BR>CONN_STRING = CONN_STRING & "MaxBufferSize=512;MaxScanRows=8;PageTimeout=5;"<B R>CONN_STRING = CONN_STRING & "SafeTransactions=0;Threads=3;UserCommitSync=Yes;" <BR>CONN_USER = ""<BR>CONN_PASS = ""<BR><BR><BR><BR>&#039 BEGIN RUNTIME CODE<BR>&#039 Declare our vars<BR>Dim iPageSize &#039How big our pages are<BR>Dim iPageCount &#039The number of pages we get back<BR>Dim iPageCurrent &#039The page we want to show<BR>Dim sSQL &#039SQL select to limit fields<BR>Dim objPagingConn &#039The ADODB connection object<BR>Dim objPagingRS &#039The ADODB recordset object<BR>Dim I &#039Standard looping var<BR><BR>&#039 Get parameters<BR>iPageSize = 10 &#039 You could easily allow users to change this<BR>If Request.QueryString("page") = "" Then<BR> iPageCurrent = 1<BR>Else<BR> iPageCurrent = CInt(Request.QueryString("page"))<BR>End If<BR><BR>&#039 Create and open our db connection<BR>Set objPagingConn = Server.CreateObject("ADODB.Connection")<BR>objPagi ngConn.Open CONN_STRING, CONN_USER, CONN_PASS<BR><BR>&#039 Create recordset<BR>Set objPagingRS = Server.CreateObject("ADODB.Recordset")<BR><BR>&#03 9 Set cursor location and pagesize<BR>objPagingRS.CursorLocation = adUseClient<BR>objPagingRS.PageSize = iPageSize<BR><BR>sSQL = "SELECT * FROM sample ORDER BY id;"<BR><BR>&#039 Open RS<BR>objPagingRS.Open sSQL, objPagingConn, adOpenStatic, adLockReadOnly, adCmdText<BR><BR>&#039 Get the count of the pages using the given page size<BR>iPageCount = objPagingRS.PageCount<BR><BR>&#039 If the request page falls outside the acceptable range,<BR>&#039 give them the closest match (1 or max)<BR>If 1 > iPageCurrent Then iPageCurrent = 1<BR>If iPageCurrent > iPageCount Then iPageCurrent = iPageCount<BR><BR>&#039 Move to the selected page<BR>objPagingRS.AbsolutePage = iPageCurrent<BR><BR>&#039bombs out with above line becaue the iPageCurrent is -1 at this point! Once again, any help is appreciated.<BR><BR><BR>Gail<BR>Gailg@gsb.com<BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    552

    Default RE: Help with PageCount Property when Paging thru recordset

    This is a stab in the dark, but are you including ADOVBS.inc?

  3. #3
    Join Date
    Dec 1969
    Posts
    13

    Default RE: Help with PageCount Property when Paging thru recordset

    Yes, it&#039s right at the top. I just tested it by printing out a constant, so it is finding it! ThanX for trying.

  4. #4
    Join Date
    Dec 1969
    Posts
    20

    Default RE: Help with PageCount Property when Paging thru recordset

    I&#039m not positive but I think it can be the ODBC driver for Access that is your problem. I don&#039t believe it supports PageCount at all, or not very well. I remember reading something about this on the MSN site. It also has a problem with RecordCount, I believe. If you find out another way to display records by pages, would appreciate an email.<BR><BR>Tim<BR>tsilva@unexmail.ucdavis.edu


  5. #5
    Join Date
    Dec 1969
    Posts
    13

    Default RE: Help with PageCount Property when Paging thru recordset

    Thank you for pointing me in the right direction. You can use RecordCount, etc, with Access as long as you have ADO 2.0. Microsoft Q202125 gives an example with Access 97. (Assuming their example works!) You must use a client side cursor (I did)and it stresses ADO 2.0. I don&#039t believe that I have that version installed and will do so today. Will post results once that is done!

  6. #6
    Join Date
    Dec 1969
    Posts
    13

    Default solved!

    The problem with paging was due to an incorrect cursor type. While I was using adovb.inc, what I didn&#039t verify is that "adUseClient" was set to "3". It was set to "1". Once I set it to "3" everything worked. (I&#039m not sure where I got that copy of adovb.inc, but I&#039m pretty sure it was Microsoft somewhere.) Microsoft Article Q202125 gives a working sample of paging.

Posting Permissions

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