Results 1 to 8 of 8

Thread: ADO rst.recordcount=-1 why?????

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    didn't decide yet
    Posts
    222

    ADO rst.recordcount=-1 why?????

    what am i doing wrong ????

    VB Code:
    1. Set cnn = New ADODB.Connection
    2. strCnn = ADO_PROVIDER & DATA_SOURCE & App.Path & DBNAME
    3. cnn.Open strCnn
    4. Set rst = New ADODB.Recordset
    5. Set cmd.ActiveConnection = cnn
    6. cmd.CommandText = "tblFirstn"
    7. cmd.CommandType = adCmdTable
    8. Set rst = cmd.Execute
    9.  
    10.  
    11. Debug.Print rst.RecordCount

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Location
    didn't decide yet
    Posts
    222
    not much cuase if u executed the code u can see that when u
    VB Code:
    1. Set rst=cmd.Execute

    then the cursortype changes to adOpenDynamic
    and the cursorlocation to adUseServer

    how can i change those proprties I m still confused please some more help

    thnks

  4. #4
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    FL
    Posts
    258
    When you use the Connection Object to return a Recordset, it returns a Forward Only, Read Only Recordset. A Forward Only Recordset does not support the RecordCount. If you really need a count you could either open a Recordset Object to get the Recordset, make it not ForwardOnly cursor.
    Or you could use the Connection object to return a count then return the recordset. If you are using SQL Server or a Db that can handle mutiple SQL statements in one query then you can combine them in one execute.

    VB Code:
    1. Dim rs As ADODB.Recordset
    2. Dim cmd As ADODB.Command
    3. Dim cn As ADODB.Connection
    4.  
    5. Set rs = New ADODB.Recordset
    6. Set cmd = New ADODB.Command
    7. Set cn = New ADODB.Connection
    8.  
    9. Dim SQL String
    10.  
    11. SQL = "SELECT COUNT(*) FROM T_OBJECT;" & "SELECT * FROM T_OBJECT"
    12.  
    13. cn.Open "DSN=CRS", "sa"
    14. cmd.CommandText = SQL
    15. cmd.ActiveConnection = cn
    16. cmd.CommandType = adCmdText
    17. Set rs = cmd.Execute(SQL)
    18.  
    19. ' rs(0) will be the record count
    20. Debug.Print rs(0)
    21.  
    22. Set rs = rs.NextRecordset
    23. ' rs will now be the recordset you want

  5. #5
    Lively Member
    Join Date
    May 2001
    Location
    Jordan\Amman
    Posts
    84
    In many cases ,the recordcount can not reflect the actual count unless you perform a MoveLast

    Try moving last before quering the recordCount
    Palestine will be free again ,and someday all the unjustice will be from the history.

  6. #6
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    FL
    Posts
    258
    Yes in many cases, mainly DAO recordsets, but not in this case.

  7. #7
    Lively Member
    Join Date
    Nov 2000
    Location
    Posts
    124
    I faced the same problem and I changed the cursur type to adOpenStatic. It solved my problem

  8. #8
    noGuru
    Guest
    only "static" / "readonly" will give you a recordcount.

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