Using an OleDb connection to access data

I have opened up a connection to a database using this method
Dim MyDatabase As OleDb.OleDbConnection
        Dim ConnectToMyDatabase As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
             "Data Source=server\file.mdb"
        MyDatabase = New OleDb.OleDbConnection(ConnectToMyDatabase)
        MyDatabase.Open()

Open in new window


and I want to take the data in the table and put it into a recordset or any other means of putting it into a variable

I have tried using code like
stringx = MyDatabase.500_Job_Robocopy

Open in new window


and this doesn't work
mjelecAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ddayx10Commented:
Perhaps this will help you.
'variable that will hold the data
Dim dTable As New System.Data.DataTable

Dim ConnectToMyDatabase As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=server\file.mdb"
'Simplified createion of connection object
Dim MyDatabase As New System.Data.OleDb.OleDbConnection(ConnectToMyDatabase)

Using MyDatabase 'will help manage resourses more cleanly
   'Need define a command to run against your connection
    Dim cmd As New System.Data.OleDb.OleDbCommand("SELECT * FROM YOURTABLENAME", MyDatabase)
    MyDatabase.Open()

    Using dr As System.Data.OleDb.OleDbDataReader = cmd.ExecuteReader 'will help manage reader more cleanly
      'can use a datatable to store the results
       dTable.Load(cmd.ExecuteReader)
    End Using
End Using

'can get the results out of "variable" using various means
   For Each dRow As System.Data.DataRow In dTable.Rows
     Dim column1 As String = dRow("ColumnName")
     'OR
     Dim column1Alt As String = dRow(0)
     ''etc
   Next

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.