Hello, I'm a newbie working with vbnet but i'm trying to create a project were I enter a name in a textbox and save it to a access database.

I'm trying to create the OledbConnection but i'm getting this error:

"oleDbException was unhandled"

this is the code i'm using:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con = New OleDbConnection("provider=microsoft.jet.oledb.4.0; data source= pract.mbd")
        da = New OleDbDataAdapter("select*from emp", con)
        cb = New OleDbCommandBuilder(da)
        ds = New DataSet
        da.Fill(ds, "emp")
    End Sub

Thanks!!!!!

Recommended Answers

All 4 Replies

Your file extension for the access database should be .mdb not .mbd I'd start there.
Also there should be no space after the semicolon. I also never have a space before or after my equal sign.

Try the following:

Dim con as New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=pract.mdb")

Maybe you have to write the full path to the database:

"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\Folder1\Folder2\LocalAccess40.mdb"

Put the following in your code window with the Imports System.Data.OleDb and run it maybe from the Form Load event.

Private Sub TEST()

    Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=pract.mdb")
    Try
      con.Open()
    Catch ex As Exception
      MsgBox(ex.ToString)
    Finally
      con.Close()

    End Try

  End Sub    End Try

If there is an exception, you will see it in the Message Box and be able to determine what is wrong.

Thanks! already tried with the code and the name of the database extension, that was the problem you were right, and now It is working perfectly so far! Thanks for the help again! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.