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)

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
Who is Participating?
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)

    Using dr As System.Data.OleDb.OleDbDataReader = cmd.ExecuteReader 'will help manage reader more cleanly
      'can use a datatable to store the results
    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")
     Dim column1Alt As String = dRow(0)

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.