Public Shared Function fetchData(ByVal fileName As String, ByVal table As String) As DataSet
Dim oConnect As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & fileName & ";User ID=Admin;Password=" 'Define connection string
Dim oQuery As String = "SELECT * FROM " & table 'Query String
Dim oConn As OleDbConnection = New OleDbConnection(oConnect) 'Define the connectors
Dim oComm As OleDbCommand = New OleDbCommand(oQuery, oConn)
Dim oData As OleDbDataAdapter = New OleDbDataAdapter(oQuery, oConn)
Dim resultSet As New DataSet
Try
oConn.Open() 'Open connection
oData.Fill(resultSet, table) 'Fill dataset
oConn.Close() 'Close connection
Catch ex As OleDb.OleDbException
Catch ex As Exception 'Show error message and exit
MsgBox(ex.Message & vbCrLf & ex.StackTrace)
Finally 'Dispose the connector objects
If Not (oConn Is Nothing) Then oConn.Dispose()
oConn = Nothing
If Not (oComm Is Nothing) Then oComm.Dispose()
oComm = Nothing
If Not (oData Is Nothing) Then oData.Dispose()
oData = Nothing
End Try
Return resultSet 'Return results
End Function