954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problems with OleDbConnection Path Help! ):

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!!!!!

Plantcode
Newbie Poster
3 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

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")
Phasma
Junior Poster in Training
81 posts since Nov 2008
Reputation Points: 21
Solved Threads: 21
 

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

"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\Folder1\Folder2\LocalAccess40.mdb"
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
 

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.

Phasma
Junior Poster in Training
81 posts since Nov 2008
Reputation Points: 21
Solved Threads: 21
 

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! :)

Plantcode
Newbie Poster
3 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: