Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add and retrieve data to and from array

Status
Not open for further replies.

ktucci

Programmer
Apr 23, 2001
146
0
0
US
i need to store this data returned from a recordset in some sort of an array or collection by looping through the result set:

key,f1,f2

1,aaa1,aaaa
1,aaa2,bbbb
1,aaa3,cccc
2,bbb1,aaaa
2,bbb2,bbbb
3,ccc1,aaaa

i would then need to retrieve all of the data by requesting the key

eg: i would want the data with a key of 1 sent to my listview

i know this probably sounds easy but can someone get me started in the right direction

ant help will be greatly appreciated

thanks

keith

 
To get the data into an array, assuming a recordset called "rs" which already has data in it:

Dim DatArray(2, rs.RecordCount - 1)

rs.MoveFirst

For r = 0 to rs.RecordCount - 1
For c = 0 to 2
DatArray(c, r) = rs.Fields(c).Value
Next c

rs.MoveNext
Next r

As for getting the data into a ListView, I have no clue. Anyone else have an idea about this?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Hi,

Why not just use the filter property on the recordset and move through the data set, rather than store the data in an array?

eg
Code:
    With DE.rsDATA
        .Filter = "Field1 = 1" ' Assumes field 1 is numeric definition
        List1.Clear
        If Not .BOF Then
            While Not .EOF
                List1.AddItem !Field2 ' display field2 in list
                .MoveNext
            Wend
        End If
    End With

Hope this helps ...
 
>Why not just use the filter property on the recordset and move through the data set, rather than store the data in an array?

Depending on the needs, this may be a useful solution.
If there is a problem using the same recordset as the original, then create the original recordset with a client side cursor, clone it, and then disconnect the clone it from the source.

Assumes rsOriginal was opened using a client side cursor:

Dim rsClone As ADODB.Recordset
Set rsClone = rsOriginal.Clone
Set rsClone.ActiveConnection = Nothing

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top