In this block of code I am simply trying to open an access 2010 database (accdb) and fill a data table. However when code is run I get
error [IM002][Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.
On a different form I use a DataGridView, DataSet, BindingSource and a
TableAdapter for the toolbox to open and view the same table, which functions fine.
The web is pointing me to the connection str, however I cannot find what is wrong. Any help is of course appreciated
Code:
Imports System.Data.Odbc
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim conn As OdbcConnection
Dim cmd As OdbcCommand
Dim da As OdbcDataAdapter
Dim query As String
Dim connString As String = ""
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Rick\Desktop\Aeroparts.accdb;Persist Security Info=False;"
query = "SELECT[*] FROM [Statuscodes]"
'Create the connection object
conn = New OdbcConnection(connString)
'Open connection
cmd = New OdbcCommand(query, conn)
da = New OdbcDataAdapter(cmd)
Dim AeroPartsDataSet = New DataSet()
Dim StationTimeTable As DataTable = AeroPartsDataSet.Tables.Add("StationTimeTable")
Try
conn.Open()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
Try
'da.Fill(StationTimeTable)
da.Dispose() 'close data adapter
conn.Close() 'close connect to Spreadsheet
conn.Dispose() 'do cleanup of connection enviroment
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
End Class