Connecting to an access database

OMRebel

Active member
Joined
Sep 27, 2006
Messages
44
Programming Experience
Beginner
Hello. I have an access database named profees.mdb. Inside of it is a table named tblInsurance. However, whenever I tried to fill the dataset in my code, I get an error saying,
"The Microsoft Jet database engine cannot find the input table or query 'tblInsurance'. Make sure it exists and that its name is spelled correctly."

Below is my very simple code:

VB.NET:
Imports System.Data

Public Class test


    Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click

        ' Setup Connection Object; con will hold the connection object
        Dim con As New OleDb.OleDbConnection

        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter    ' Data adapter
        Dim sql As String

        ' Setup the Connection String; con is the connection string
        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = \profees.mdb"

        ' Open the connection to the database
        con.Open()

        sql = "Select * From tblInsurance"
        ' Create the data adapter
        da = New OleDb.OleDbDataAdapter(sql, con)
        ' Fill the dataset from the data adapter
        da.Fill(ds, "ProFees")

        MsgBox("A Connection to the Database is now open")

        ' Close the connection to the database
        con.Close()
        MsgBox("The Connection to the Database is now Closed")

    End Sub

End Class
 
I haven't looked at you code very close but here are a few ideas:

1. Surround the fill with a try and catch the error and display the
error in a msgbox ..something like msgbox(ex.message)

2. See program imports:
imports system.data.oledb
imports system.data.sqlClient

3. You may need to create a MDW file
 
i suggest that you double check the name of the table - rename it to Z and adjust the query - does it still not work?
 
The problem was the location of the table was wrong that I had in my path. Thanks to you two for the suggestions. I'm getting the hang of VB finally. :)
 
Back
Top