vb 2005 express > querry table in access and put contents into array

D

ducky801

Hi all,

I've got some general VB experience, but i'm not sure how to approach
the problem at hand. here is what i've got:

I have a database that holds employee data (access database). I want
to make vb 2005 express look in a table (called 'EmpData') and extract
the phone login ID's for all of the agents in the table who are still
employed or who have not left the company yet (but may have a future
end date). i want to store each of those phone logins in an array,
which is used by another procedure to extract phone usage statistics.

so the SQL statement would look like this:

(SELECT EmpData.PhoneLogin FROM EmpData WHERE (((EmpData.EndDate) Is
Null Or (EmpData.EndDate)>Now()));)

i just don't know how to make VB execute this statement and store the
results in an array??? also, will i need a 1 dimensional or 2
dimensional array for this (since i want to store 'PhoneLogin', but i'm
using 'EndDate' to get the desired results)?

Any help is greatly appreciated.

TIA

AR
 
A

adm

Rather than store the results in an array, you want to use a datareader
or store them in a data table within a dataset, then loop through the
rows in the data table to do whatever you were planning to do with that
array.

For more info on the data reader technique, see:
http://visualbasic.about.com/od/usingvbnet/l/aa050303c.htm

Basically, you need to set up an OleDbAdapter to connect to the Access
database, and then go from there. Slightly adapting the code from the
link above:

Dim strConn As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" _
& "User ID=Admin;" _
& "{path}\"employees.mdb"
Dim ocmd As OleDbCommand
Dim odtr As OleDbDataReader

ocmd = New OleDbCommand()
With ocmd
.Connection = New _
OleDbConnection(stConn)
.Connection.Open()
.CommandText = "Select * From Employees"
odtr = .ExecuteReader()
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top