Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse ADO's GetRows method to quickly load data into an array
KeywordsADO, database, load array, fill array, GetRows
CategoriesDatabase
 
GetRows returns a variant array holding the Recordset's values. Simply assign a variant variable to this function's result. Then you can examine the values in the array instead of needing to loop through the Recordset's results.
 
Dim conn As ADODB.Connection
Dim statement As String
Dim rs As ADODB.Recordset
Dim values As Variant
Dim txt As String
Dim r As Integer
Dim c As Integer

    ' Open the database connection.
    ...

    ' Select the data.
    statement = "SELECT * FROM Books ORDER BY Title, Year"

    ' Get the records.
    Set rs = conn.Execute(statement, , adCmdText)

    ' Load the values into a variant array.
    values = rs.GetRows

    ' Close the recordset and connection.
    rs.Close
    conn.Close

    ' Use the array to build a string
    ' containing the results.
    For r = LBound(values, 2) To UBound(values, 2)
        For c = LBound(values, 1) To UBound(values, 1)
            txt = txt & values(c, r) & ", "
        Next c
        txt = Left$(txt, Len(txt) - 1) & vbCrLf
    Next r

    ' Display the results.
    txtBooks.Text = txt
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated