Dim myReader As OleDbDataReader
Dim myOleDbConnection As OleDbConnection
Dim myOleDbCommand As OleDbCommand
Dim connectionString As String
Dim sqlQuery As String
' Initialize variables
' Connection Less (connection string):
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\temp;" & _
"Extended Properties=DBASE III;"
'connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Dsn=MyContactList"
' SQL Statement to execute on the database
sqlQuery = "SELECT Examiner FROM Workload.dbf "
' Instantiate the connection and the command
myOleDbConnection = New OleDbConnection(connectionString)
myOleDbCommand = New OleDbCommand(sqlQuery, myOleDbConnection)
Try ' error handling code (try and do the following)
' Open the connection with the database
myOleDbConnection.Open()
' Execute the SQL command and populate the data reader
myReader = myOleDbCommand.ExecuteReader()
' Loop through the contents of the data reader
Do While (myReader.Read)
' Each time through the loop represents one record being returned
' Put the email address from the data reader into the form
txtOpenedFile.Text = txtOpenedFile.Text & myReader("Examiner") & vbCrLf
Loop ' End of Loop (any particular record)
Catch ex As Exception
' an error has occured execute the following
Debug.WriteLine(ex.Message)
Finally
' Regardless of what happened this code will execute
' Close the data reader
If Not (myReader Is Nothing) Then
myReader.Close()
End If
' Close the connection to the database
If (myOleDbConnection.State = ConnectionState.Open) Then
myOleDbConnection.Close()
End If
' Memory Management / Garbage Collection
myReader = Nothing
myOleDbConnection = Nothing
myOleDbCommand = Nothing
End Try
End Sub
End Class