简体   繁体   中英

How to select 1 field from database then store to array in vb6

How to get all the id numbers in database then store all id numbers to array in vb6?

Or is there another way to store all id numbers in one variable only? Because later in the program, I will use the id numbers one by one.

The GetRows method of an ADO recordset returns an array.

This sample opens the table as a recordset and loads its id values into an array.

Dim rs As Object
Dim varGetRows As Variant

Set rs = CreateObject("ADODB.Recordset")
rs.Open "tblFoo", CurrentProject.Connection
varGetRows = rs.GetRows(, , "id")

I don't know what you want to do with the array, so I'll just examine its values ...

Dim lngUBound As Long
Dim i As Long

lngUBound = UBound(varGetRows, 2)
For i = 0 To lngUBound
    Debug.Print varGetRows(0, i)
Next i

If you're interested in something other than an array, you could use a Collection or Dictionary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM