VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Extract the data from an ADO Recordset into a 2-D variant array

by Tammy Cravit (1 Submission)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 29th February 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Extract the data from an ADO Recordset into a 2-D variant array

Rate Extract the data from an ADO Recordset into a 2-D variant array




    Dim avarStuff() As Variant      ' Hold the returned records
    Dim fldThis As ADODB.Field      ' Iterator for the Fields collection
    Dim iIndex As Integer           ' Loop index
    
    ' Resize the array to hold the column names
    ReDim avarStuff(1 To oRst.Fields.Count, 0 To 0) As Variant
    
    ' Extract all the column names from the Fields collection
    iIndex = 1
    For Each fldThis In oRst.Fields
        avarStuff(iIndex, 0) = fldThis.Name
        iIndex = iIndex + 1
    Next fldThis
    
    ' Move to the first record in the recordset
    oRst.MoveFirst
    
    ' Loop through the records, and build the 2-D array
    Do While Not oRst.EOF
        ReDim Preserve avarStuff(LBound(avarStuff, 1) To UBound(avarStuff, 1), _
            LBound(avarStuff, 2) To (UBound(avarStuff, 2) + 1)) As Variant
            
        For iIndex = LBound(avarStuff, 1) To UBound(avarStuff, 1)
            avarStuff(iIndex, UBound(avarStuff, 2)) = _
                oRst.Fields(avarStuff(iIndex, 0)).Value
        Next iIndex
        
        oRst.MoveNext
    Loop
    
    ' Return the array
    RecordsetToVarArray = avarStuff()
End Function


Download this snippet    Add to My Saved Code

Extract the data from an ADO Recordset into a 2-D variant array Comments

No comments have been posted about Extract the data from an ADO Recordset into a 2-D variant array. Why not be the first to post a comment about Extract the data from an ADO Recordset into a 2-D variant array.

Post your comment

Subject:
Message:
0/1000 characters