Paged RecordSet Advice

  • anyusernamewilldo
  • Novice
  • Novice
  • anyusernamewilldo
  • Posts: 22

Post 3+ Months Ago

Hey All,

I'm trying to limit the amount of results per page... However I'm Receiving the Following Error:

Provider error '80020005'
Type mismatch.
/asp/paging/pagingtest.asp, line 26



When I'm Running the following code:
I've highlighted the Above Error in red in the Script Below

Code: [ Select ]
<%
 
Dim objRS, objConn,
 
 
objConn = "Provider=Microsoft.Jet.OLEDB.4.0; objConn=" & _
    Server.MapPath("downloadform.mdb")
 
' Creating Recordset Object
Set objRS = Server.CreateObject("ADODB.Recordset")
 
    'How many records per page
    Const iRecordsPerPage = 10
 
    Dim currentPage  'what page are we on??
    Dim bolLastPage  'are we on the last page?
   
    if len(Request.QueryString("page")) = 0 then
        currentPage = 1
    else
        currentPage = CInt(Request.QueryString("page"))
    end if
 
    'Show the paged results
    strSQL = "sp_PagedItems " & currentPage & "," & iRecordsPerPage
    objRS.Open "SELECT * FROM users ORDER BY id DESC", strSQL, objConn
   
    'See if we're on the last page
    if Not objRS.EOF then
        if CInt(objRS("MoreRecords")) > 0 then
            bolLastPage = False
        else
            bolLastPage = True
        end if
    end if
%>
  1. <%
  2.  
  3. Dim objRS, objConn,
  4.  
  5.  
  6. objConn = "Provider=Microsoft.Jet.OLEDB.4.0; objConn=" & _
  7.     Server.MapPath("downloadform.mdb")
  8.  
  9. ' Creating Recordset Object
  10. Set objRS = Server.CreateObject("ADODB.Recordset")
  11.  
  12.     'How many records per page
  13.     Const iRecordsPerPage = 10
  14.  
  15.     Dim currentPage  'what page are we on??
  16.     Dim bolLastPage  'are we on the last page?
  17.    
  18.     if len(Request.QueryString("page")) = 0 then
  19.         currentPage = 1
  20.     else
  21.         currentPage = CInt(Request.QueryString("page"))
  22.     end if
  23.  
  24.     'Show the paged results
  25.     strSQL = "sp_PagedItems " & currentPage & "," & iRecordsPerPage
  26.     objRS.Open "SELECT * FROM users ORDER BY id DESC", strSQL, objConn
  27.    
  28.     'See if we're on the last page
  29.     if Not objRS.EOF then
  30.         if CInt(objRS("MoreRecords")) > 0 then
  31.             bolLastPage = False
  32.         else
  33.             bolLastPage = True
  34.         end if
  35.     end if
  36. %>




I'm totally Stuck... Thanks In Advance for any help Guys.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • anyusernamewilldo
  • Novice
  • Novice
  • anyusernamewilldo
  • Posts: 22

Post 3+ Months Ago

Cancel that, I scrapped that idea after some further research into Paged Recordsets....

I've solved my needs with the following Code:
maybe it will save some of you the headaches and hurdles i've gone through researching Paging Records!

Code: [ Select ]
<%
 Dim connStr
  connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
   Server.MapPath("downloadform.mdb")
 
 Dim rs
  Set rs = Server.CreateObject("ADODB.Recordset")
 
  rs.PageSize = 20
  rs.CacheSize = 20
  rs.CursorLocation = adUseClient
 
 rs.Open "SELECT * FROM users ORDER BY id DESC", connStr, adOpenForwardOnly, adLockReadOnly, _
  adCmdTableDirect
 
 If Len(Request("pagenum")) = 0  Then
  rs.AbsolutePage = 1
 Else
  If CInt(Request("pagenum")) <= rs.PageCount Then
   rs.AbsolutePage = Request("pagenum")
  Else
   rs.AbsolutePage = 1
  End If
 End If
 
 Dim abspage, pagecnt
  abspage = rs.AbsolutePage
  pagecnt = rs.PageCount
 
 If Not rs.EOF Then
  Response.Write "PageCount : " & rs.PageCount & "<br>" & vbcrlf
  Response.Write "Absolute Page : " & rs.AbsolutePage & "<br>" & vbcrlf
 
  Response.Write "Total number of records : " & rs.RecordCount
  Response.Write "<br><br>" & vbcrlf
 
  Dim fldF, intRec
  ' Design your own layout for Results Page Here:
 Response.Write "<table border=1 align=center cellpadding=3 "
  Response.Write "cellspacing=0><thead><tr>"
  For Each fldF in rs.Fields
   Response.Write "<td>" & fldF.Name & "</td>"
  Next
  Response.Write "</tr></thead><tbody>"
 
  For intRec=1 To rs.PageSize
   If Not rs.EOF Then
    Response.Write "<tr>"
    Response.Write "<td>   <strong>Name :</strong> " & rs("name") & "</td>"
    Response.Write "<td>   <strong>Date :</strong> " & rs("dateposted") & "</td>"
    Response.Write "<td>   <strong>File Size :</strong> " & rs("comments") & "</td>"
    Response.Write "<td>   <strong>Link :</strong> <a href='" & rs("topic") & "'>" & "File Link" & "</a>" & "</td>"
    Response.Write "<td>   <input type='hidden' name='id' value='" & rs("id") & "'> </td>"
    Response.Write "<tr>"

    rs.MoveNext
   End If
  Next
  Response.Write "</tbody></table><p>"
 
' Now showing first, next, back, last buttons.
 
Response.Write "<div align=""center"">" & vbcrlf
Response.Write "<a href="""
Response.Write Request.ServerVariables("SCRIPT_NAME")
Response.Write "?pagenum=1""><b>First Page</b></a>"
Response.Write "    |   "
 
If abspage = 1 Then
    Response.Write "<span style=""color:silver;"">Previous Page</span>"
Else
    Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME")
    Response.Write "?pagenum=" & abspage - 1 & """><b>Previous Page</b></a>"
End If
 
Response.Write "    |   "
    If abspage < pagecnt Then
        Response.Write "<a href=""" & _
            Request.ServerVariables("SCRIPT_NAME")
        Response.Write "?pagenum=" & abspage + 1 & """>Next Page</a>"
    Else
        Response.Write "<span style=""color:silver;""" & _
            "><b>Next Page</b></span>"
End If
 
Response.Write "    |   "
Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME")
    Response.Write "?pagenum=" & pagecnt & """><b>Last Page</b></a>"
Response.Write "</div>" & vbcrlf
 
Else
    Response.Write "No records found!"
End If
 
rs.Close
Set rs = Nothing
 
%>
  1. <%
  2.  Dim connStr
  3.   connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
  4.    Server.MapPath("downloadform.mdb")
  5.  
  6.  Dim rs
  7.   Set rs = Server.CreateObject("ADODB.Recordset")
  8.  
  9.   rs.PageSize = 20
  10.   rs.CacheSize = 20
  11.   rs.CursorLocation = adUseClient
  12.  
  13.  rs.Open "SELECT * FROM users ORDER BY id DESC", connStr, adOpenForwardOnly, adLockReadOnly, _
  14.   adCmdTableDirect
  15.  
  16.  If Len(Request("pagenum")) = 0  Then
  17.   rs.AbsolutePage = 1
  18.  Else
  19.   If CInt(Request("pagenum")) <= rs.PageCount Then
  20.    rs.AbsolutePage = Request("pagenum")
  21.   Else
  22.    rs.AbsolutePage = 1
  23.   End If
  24.  End If
  25.  
  26.  Dim abspage, pagecnt
  27.   abspage = rs.AbsolutePage
  28.   pagecnt = rs.PageCount
  29.  
  30.  If Not rs.EOF Then
  31.   Response.Write "PageCount : " & rs.PageCount & "<br>" & vbcrlf
  32.   Response.Write "Absolute Page : " & rs.AbsolutePage & "<br>" & vbcrlf
  33.  
  34.   Response.Write "Total number of records : " & rs.RecordCount
  35.   Response.Write "<br><br>" & vbcrlf
  36.  
  37.   Dim fldF, intRec
  38.   ' Design your own layout for Results Page Here:
  39.  Response.Write "<table border=1 align=center cellpadding=3 "
  40.   Response.Write "cellspacing=0><thead><tr>"
  41.   For Each fldF in rs.Fields
  42.    Response.Write "<td>" & fldF.Name & "</td>"
  43.   Next
  44.   Response.Write "</tr></thead><tbody>"
  45.  
  46.   For intRec=1 To rs.PageSize
  47.    If Not rs.EOF Then
  48.     Response.Write "<tr>"
  49.     Response.Write "<td>   <strong>Name :</strong> " & rs("name") & "</td>"
  50.     Response.Write "<td>   <strong>Date :</strong> " & rs("dateposted") & "</td>"
  51.     Response.Write "<td>   <strong>File Size :</strong> " & rs("comments") & "</td>"
  52.     Response.Write "<td>   <strong>Link :</strong> <a href='" & rs("topic") & "'>" & "File Link" & "</a>" & "</td>"
  53.     Response.Write "<td>   <input type='hidden' name='id' value='" & rs("id") & "'> </td>"
  54.     Response.Write "<tr>"
  55.     rs.MoveNext
  56.    End If
  57.   Next
  58.   Response.Write "</tbody></table><p>"
  59.  
  60. ' Now showing first, next, back, last buttons.
  61.  
  62. Response.Write "<div align=""center"">" & vbcrlf
  63. Response.Write "<a href="""
  64. Response.Write Request.ServerVariables("SCRIPT_NAME")
  65. Response.Write "?pagenum=1""><b>First Page</b></a>"
  66. Response.Write "    |   "
  67.  
  68. If abspage = 1 Then
  69.     Response.Write "<span style=""color:silver;"">Previous Page</span>"
  70. Else
  71.     Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME")
  72.     Response.Write "?pagenum=" & abspage - 1 & """><b>Previous Page</b></a>"
  73. End If
  74.  
  75. Response.Write "    |   "
  76.     If abspage < pagecnt Then
  77.         Response.Write "<a href=""" & _
  78.             Request.ServerVariables("SCRIPT_NAME")
  79.         Response.Write "?pagenum=" & abspage + 1 & """>Next Page</a>"
  80.     Else
  81.         Response.Write "<span style=""color:silver;""" & _
  82.             "><b>Next Page</b></span>"
  83. End If
  84.  
  85. Response.Write "    |   "
  86. Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME")
  87.     Response.Write "?pagenum=" & pagecnt & """><b>Last Page</b></a>"
  88. Response.Write "</div>" & vbcrlf
  89.  
  90. Else
  91.     Response.Write "No records found!"
  92. End If
  93.  
  94. rs.Close
  95. Set rs = Nothing
  96.  
  97. %>



I'm going to sleep well tonight :D
Jy

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 80 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.