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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populating an array from a table

Status
Not open for further replies.

campbere

Technical User
Joined
Oct 10, 2000
Messages
146
Location
US
I am working with a VB 6.0 application that sits on top of an Oracle database.

In a table called products I have several columns. One column is called titles. I want to grab all distinct titles and insert them into an array.

I then use the array in a for loop to evaluate each distinct title one at a time.

How do I populate an array from a table? I don't want to
create any additional tables, which is why I thought of using an array.
 
You can use a recordset instead of the array. Since it sounds like having the array would be double duty. You can use the following example written in ADO to do what you need. I didn't test this code, I just typed it in, in the forum. Be sure to add a reference to MS Active Data Objects 2.5, 2.1 or 2.0, depending on what version you have installed. You this code at your own discresion.

SELECT DISTINCT titles FROM products

Then to do your evalutation you can use code something like this:

Dim cnnOracle As ADODB.Connection
Dim rs As ADODB.Recordset

set cnnOracle = New ADODB.Connection

cnnOracle.Open &quot;<your DSN name here>&quot;, &quot;<UserID&quot;, &quot;<Password>&quot;

strSQL = &quot;SELECT DISTINCT titles FROM products&quot;

set rs = New ADODB.Recordset
rs.Open strSQL, cnnOracle

Do Until rs.EOF
If <your check goes here> = rs!Title Then
<Do custom stuff here>
End If

rs.MoveNext
Loop

rs.Close
Set rs = Nothing

cnnOracle.Close
Set cnnOracle = Nothing Snaggs
tribesaddict@swbell.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top