ADO RecordSet Paging

Results 1 to 6 of 6

Thread: ADO RecordSet Paging

  1. #1
    Join Date
    Dec 1969
    Posts
    226

    Default ADO RecordSet Paging

    I use a query and my database is just too big without using some<BR>kind of paging.<BR><BR>I tried using the Recordset to page through the database. When I enter a query, It finds the user but when I hit next it gives me the 2nd page of my recordset instead of the 2nd page of my query.<BR><BR>Someone Please help because I am starting to lose it.

  2. #2
    Jairo Guest

    Default RE: ADO RecordSet Paging

    Can you explain your problem again? I didn&#039t catch it the first time.<BR>Thanks,<BR>Jairo<BR>http:/www.citywebarchitects.com

  3. #3
    Join Date
    Dec 1969
    Posts
    226

    Default RE: ADO RecordSet Paging

    Sure I can, Thanks!!<BR><BR> I am using the Connection and Recordset Objects to Search through an Access Database. My Database is really big (147,000 records). This is why I have to let the user Page through the data. <BR> <BR> I am using the code that this web-site provided.It seems that when I search for someone in the database it finds them. <BR>When I want to page through to the next page of the data, instead of giving me the data for the next page of my search, it gives me the the next page of the start of the Database.<BR><BR> Example( I have 5 records, Anthony, Bob, Cory, Dillon and Enzo.) If I search for Cory, on the next page it should give me Dillon then Enzo but what I get is Bob then Cory and so on. <BR><BR> Here is the URL of the code that I used, I hope you can shed some light on my problem because I am really getting stumped.<BR><BR>http://www.4guysfromrolla.com/webtech/121298-1.shtml

  4. #4
    Jairo Guest

    Default RE: ADO RecordSet Paging

    George,<BR>If your source code isn&#039t huge, then post the source here. If it is too big, feel free to send it over to me at jairo@citywebarchitects.com.<BR><BR>I&#039ll take a look at it and see if I can help you out.<BR>HTH,<BR>Jairo<BR>http://www.citywebarchitects.com


  5. #5
    Join Date
    Dec 1969
    Posts
    226

    Default RE: ADO RecordSet Paging

    Hey Jairo,<BR><BR>I sent you all the code including the htm and js files also but I decided to put this up as well in case anybody else finds it interesting. Thanks Again.<BR><BR><BR>&#060;%@ LANGUAGE="VBSCRIPT" %&#062;<BR><BR><BR>&#060;%<BR>&#039---- CursorTypeEnum Values ----<BR>Const adOpenForwardOnly = 0<BR>Const adOpenKeyset = 1<BR>Const adOpenDynamic = 2<BR>Const adOpenStatic = 3<BR><BR>&#039---- CursorLocationEnum Values ----<BR>Const adUseServer = 2<BR>Const adUseClient = 3<BR><BR><BR><BR>lastname = replace(Request.Form("txt_lastname"), "&#039","&#039&#039")<BR>firstname = replace(Request.Form("txt_firstname"),"&#039","&#0 39&#039")<BR><BR><BR> &#039Set how many records per page we want<BR> Const NumPerPage = 10<BR><BR> &#039Retrieve what page we&#039re currently on<BR> Dim CurPage<BR> If Request.QueryString("CurPage") = "" then<BR> CurPage = 1 &#039We&#039re on the first page<BR> Else<BR> CurPage = Request.QueryString("CurPage")<BR> End If<BR><BR> Dim conn<BR> Set conn = Server.CreateObject("ADODB.Connection")<BR> conn.Open "DATABASE=george;DSN=J4Mat;uid=;pwd;"<BR><BR> &#039Explicitly Create a recordset object<BR> Dim rs<BR> Set rs = Server.CreateObject("ADODB.Recordset")<BR><BR> &#039Set the cursor location property<BR> rs.CursorLocation = adUseClient<BR><BR> &#039Set the cache size = to the # of records/page<BR> rs.CacheSize=NumPerPage<BR><BR> &#039Open our recordset<BR> Dim strSQL<BR><BR><BR> strSQL = "select Last_Name, First_Name from george where Last_Name like &#039" & trim(lastname) & "%&#039 and First_Name like &#039" & trim(firstname) &"%&#039 ORDER BY Last_Name, First_Name"<BR><BR><BR><BR> <BR> rs.Open strSQL, Conn<BR><BR> rs.MoveFirst<BR> rs.PageSize = NumPerPage<BR><BR> &#039Get the max number of pages<BR> Dim TotalPages<BR> TotalPages = rs.PageCount<BR><BR> &#039Set the absolute page<BR> rs.AbsolutePage = CurPage<BR><BR> &#039Counting variable for our recordset<BR> Dim count<BR>%&#062;<BR><BR>&#060;HTML&#062;<BR>&#060; BODY&#062;<BR>&#060;B&#062;Last Name - First Name&#060;/B&#062;<BR><BR>&#060;%<BR> &#039Set Count equal to zero<BR> Count = 0<BR> Do While Not rs.EOF And Count &#060; rs.PageSize<BR> Response.Write(rs.Fields("Last_Name") & " - " & rs.Fields("First_Name") & "<BR>")<BR> Count = Count + 1<BR> rs.MoveNext<BR> Loop<BR><BR> &#039Print out the current page # / total pages<BR> Response.Write("Page " & CurPage & " of " & TotalPages & "&#060;P&#062;")<BR><BR> &#039Display Next / Prev buttons<BR> if CurPage &#062; 1 then<BR> &#039We are not at the beginning, show the prev button<BR> Response.Write("&#060;INPUT TYPE=BUTTON VALUE=PREV ONCLICK=""document.location.href=&#039new.asp?curp age=" & curpage - 1 & "&#039;""&#062;")<BR> End If<BR><BR>if CInt(CurPage) &#060;&#062; CInt(TotalPages) then<BR> &#039We are not at the end, show a next button<BR> Response.Write("&#060;INPUT TYPE=BUTTON VALUE=NEXT ONCLICK=""document.location.href=&#039new.asp?curp age=" & curpage + 1 & "&#039;""&#062;")<BR> End If<BR><BR>%&#062;<BR><BR>&#060;/BODY&#062;<BR>&#060;/HTML&#062;<BR><BR>&#060;% <BR> <BR> rs.close()<BR> conn.close()<BR> <BR>%&#062;<BR>

  6. #6
    Jairo Guest

    Default RE: ADO RecordSet Paging

    George,<BR>At the bottom where you redirect it back to your page, new.asp - you need to keep the form variables intact. What is happening is on the second time around, both your first and last names are blank.<BR><BR>So you&#039ll need to add both &txt_lastname=&#060;%=lastname%&#062; &txt_firstname=&#060;%=firstname%&#062; to your document.location.href in order for it to work.<BR><BR>A sample for page 2 would be new.asp?curpage=2&txt_lastname=Smith&txt_firstname =John<BR><BR>HTH,<BR>Jairo<BR>http://www.citywebarchitects.com

Posting Permissions

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