I’m trying to open a database in Visual BASIC.net. This is my code so far,
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
dbProvider = "PROVIDER=Microsoft.jet.OLEDB.4.0;"
dbSource = "Data Source = C:\Documents and Settings\somar\Desktop\Dropbox\Visual Studio 2010 VB.net\Projects\AddressBook.mbd"
con.ConnectionString = dbProvider & dbSource
con.Open()
MsgBox("Database is now open")
con.Close()
MsgBox("Database is not closed")
End Sub
The error occurs I try click the button. VB says that it is not able to fin the path to the file. I’ve changed the location to the Desktop but that didn’t change much. I’m not sure why this occurs, nay help you be greatly appreciated.
I’m fairly new to programming.
Thanks
You should probably change
mbdtomdbin your filename.You should also use
OleDbConnectionStringBuilderinstead of string concatenation, and should should use aUsingblock instead of explicitly callingClose().