SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    paging recordset returns -1

    Hi,

    I am using sql compact edition 3.5 and classic asp for one of my application, and paging recordset manually to show the report. But the pagecount returns always -1. Please help me to resolve the issue.

    Code ASP:
        Public Function PagingRecordSet (CmdText, CommandType, objClsADOParameter, intPageSize, intPageNumber)
            'intPageSize    - No. Of Records per page
            'intPageNumber    - Page Number
            Dim RowAffected, objRset, Cmd, iPageCurrent
            Set objRset = Nothing
            Set objRset = CreateObject("ADODB.RecordSet")
            Set Cmd = CreateObject("ADODB.Command")
            iPageCurrent = CLng(intPageNumber)
            Cmd.CommandType = CommandType
            Cmd.CommandText = CmdText
            Cmd.ActiveConnection = m_objCon
            If Not IsNull(objClsADOParameter) Then
                Call PrepareParameters(Cmd, objClsADOParameter)
            End If
            intPageSize = CLng(intPageSize)
            objRset.PageSize = intPageSize
            'objRset.CursorLocation = adUseClient
            objRset.CacheSize = intPageSize
     
            objRset.Open Cmd,,adOpenStatic,adLockReadOnly
            Cmd.ActiveConnection = Nothing
            iPageCount = objRset.PageCount
            If iPageCurrent > iPageCount Then
                iPageCurrent = iPageCount
            End If
            If iPageCurrent < 1 Then iPageCurrent = 1
     
            If iPageCount > 0 Then objRset.AbsolutePage = iPageCurrent
     
            Dim rsTemp, iRecordsShown, objFields, intFieldsCount
            Set rsTemp = CopyRecordsetStructure(objRset)
            rsTemp.Open
            iRecordsShown = 0
            Set objFields = objRset.Fields
            intFieldsCount = objFields.Count-1
            Dim arrValues()
            Do While iRecordsShown < intPageSize And Not objRset.EOF
                rsTemp.AddNew
                For Idx = 0 To intFieldsCount
                    rsTemp.Fields(Idx).Value = objRset.Fields(Idx).Value
                Next
                rsTemp.Update
                iRecordsShown = iRecordsShown + 1
                objRset.MoveNext
            Loop
            If Not rsTemp.EOF Then rsTemp.MoveFirst
            Set Cmd = Nothing
            Set objRset = Nothing
            Set PagingRecordSet = rsTemp
        End Function

    Thanks in advance.
    Last edited by Mittineague; May 1, 2011 at 20:36. Reason: reformatting bbcode tags

  2. #2
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    357
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Probably you've created a recordset that doesn't support pagecount.

    See RecordCount Property (ADO)
    Doug G
    =====
    "If you ain't the lead dog, the view is always the same - Anon

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Try adOpenKeyset instead of adOpenStatic. Also the link below might prove informative.

    How do I page through a recordset?
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    SitePoint Member
    Join Date
    May 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for you replies.

    still i am facing the same problem doing paging with sql server compact edition 3.5 and classic asp.


Tags for this Thread

Bookmarks

Posting Permissions

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