VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



ADO Count database rows Get total number of rows in a table fast even with millions of rows. Much f

by Troy McDowell (1 Submission)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Tue 2nd April 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

ADO Count database rows Get total number of rows in a table fast even with millions of rows. Much faster than using "SELECT COUNT(*) FROM

API Declarations



' Add a reference to Microsoft ActiveX Data Objects Library

Rate ADO Count database rows Get total number of rows in a table fast even with millions of rows. Much f




    '  Add a reference to Microsoft ActiveX Data Objects Library
    '  Code uploaded by Troy McDowell [email protected]
    Dim cn As ADODB.Connection
    Dim rsSchema As ADODB.Recordset
    Dim rCriteria As Variant
    Dim strDbPath As String
    Dim strDbTable As String
    Dim strDbPassword As String
    
    strDbPath = "c:\path\to\database.mdb"     ' Path to Database file
    strDbTable = "Table Name"                     ' Table Name
    strDbPassword = "Database Password"               ' Database Password
    
    Set cn = New ADODB.Connection
    
       With cn
          .Provider = "Microsoft.Jet.OLEDB.4.0"
          .Properties("Jet OLEDB:Database Password") = strDbPassword
          .Mode = adModeReadWrite
          .Open strDbPath
       End With
    
    rCriteria = Array(Empty, Empty, Empty, Empty, strDbTable)
    
    Set rsSchema = cn.OpenSchema(adSchemaIndexes, rCriteria)
    
    Debug.Print "Total Rows: " & rsSchema.Fields("CARDINALITY").Value
    
    rsSchema.Close
    Set rsSchema = Nothing
    cn.Close
    Set cn = Nothing

End Sub


Download this snippet    Add to My Saved Code

ADO Count database rows Get total number of rows in a table fast even with millions of rows. Much f Comments

No comments have been posted about ADO Count database rows Get total number of rows in a table fast even with millions of rows. Much f. Why not be the first to post a comment about ADO Count database rows Get total number of rows in a table fast even with millions of rows. Much f.

Post your comment

Subject:
Message:
0/1000 characters