Results 1 to 10 of 10

Thread: ADO RecordCount Property

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 1999
    Location
    Chicago
    Posts
    11

    Post

    When I use the SQLOLEDB Provider I cannont get a record count. All the documentation that I have read says I need to use Keyset or static cursor type. And then read through the recordset to get a count. I tried this and it does not work.

    Has anyone found a way to get a record count using the SQLOLEDB and using either server side or client side cursors.

    Thanks

  2. #2
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122

    Post

    use

    Recordset.MoveLast

    and then

    Recordset.RecordCount

    Roger

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    RogerH: I haven't tried it myself, but I believe that when using ADO you no longer need to do the movelast to get the recordcount like you need to do when using DAO.

    ------------------
    Marty

  4. #4
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122

    Post

    Marty,

    you will receive -1 as long as the recordset doesn't know the number of records. Alot became better in ADO, unfortunately not that matter.

    Tip: If you want to know if the recordset is empty use

    IF recset.eof and recset.bof THEN
    MSGBOX "Empty!"
    ENDIF

    This will speed things up.

    Roger

  5. #5
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    You need to specify to open the recordset as adOpenKeyset or adOpenStatic cursor to be able to get the recordcount property of the ADO Recordset, or you could use a counter and count until EOF if you are using a forward only cursor

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 1999
    Location
    Chicago
    Posts
    11

    Post

    Clunietp

    I already tried those cursor types. They don't work. The Keyset and the Static Cursor Types do not work. I still get -1 Record Count. Our other programmers have had the same problem.

    Do you have any ideas

    Jimmy

  7. #7
    Junior Member
    Join Date
    Nov 1999
    Posts
    16

    Post

    That's the code that works for me:

    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    cn.CursorLocation = adUseClient
    cn.Open "DSN=Ship2000"
    rs.Open "Select ssn from history", cn, adOpenStatic
    MsgBox rs.RecordCount

    The History table has 200013 records. For client-side cursor everything is ok. For server-side cursor it says "Timeout expires" on Open method (too many records) but with the smaller subset of records server-side keyset cursor works.

    And, i think

    Dim lngCounter As long
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    cn.CursorLocation = adUseClient
    cn.Open "DSN=Ship2000"
    rs.Open "Select ssn from history", cn, adOpenStatic
    Do While Not rs.eof
    lngCounter = lngCounter+1
    rs.MoveNext
    Loop
    MsgBox lngCounter

    should work in any case.

    Regards, Vlad

  8. #8

    Thread Starter
    New Member
    Join Date
    Dec 1999
    Location
    Chicago
    Posts
    11

    Post

    Thanks Vlad

    You have been the most helpful

    JimmyJam

  9. #9
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334

    Post

    This works for me though . . .

    rst.Open "m:\adonew\gerbil.rst", _ & "Provider=MSPersist", adOpenKeyset, _ & adLockBatchOptimistic, adCmdFile

    rst.MoveFirst

    StatusBar1.Panels(3).Text = rst.RecordCount


    I know I'm using a saved recordset but it also works using a currently open one.

    ??Matt

  10. #10
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    If you want to see the record count, then you HAVE to specify the CursorLocation as Client:

    cn.CursorLocation = adUseClient


    ------------------

    Serge

    Software Developer
    [email protected]
    ICQ#: 51055819



Posting Permissions

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



Click Here to Expand Forum to Full Width