OLEDB Connection won't connect to Access 2013 database - vb.net

I am trying to use the OLEDB connection to load my database to my Visual Basic program. However, I am receiving this error:"Could not find installable ISAM."
I am using Microsoft Access Database 2013. As far as I'm aware, 12.0 is the correct version.
This is my code:
Dim con As New OleDb.OleDbConnection
Dim databaseprovider As String
Dim dblocation As String
databaseprovider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
dblocation = "Date source = C:\HotelBookingDatabase.accdb"
con.ConnectionString = databaseprovider & dblocation
con.Open()
MsgBox("open")
con.Close()
MsgBox("closed")
Edit - I have changed "Data source..." to "Data Source..." and installed 2007 Office System drivers, but that hasn't helped my cause.
Edit #2 - Looked at the code above again today. I figured out the problem. Instead of "Data Source", my code has "DATE Source". Oops. Updated code, which works:
Dim con As New OleDb.OleDbConnection
Dim dbprovider As String
Dim dbsource As String
dbprovider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
dbsource = "Data Source = C:\HotelBookingDatabase.accdb;"
con.ConnectionString = dbprovider & dbsource
con.Open()
MsgBox("ok")
con.Close()
MsgBox("bye")

I have sorted out the problem.
I changed my code to this:
Dim con As New OleDbConnection("Provider=MICROSOFT.ACE.OLEDB.12.0; Data Source=C:\HotelBookingDatabase.accdb")
con.Open()
MsgBox("ok")
con.Close()
MsgBox("bye")

Related

Saving data to access not working, despite no errors

Hey I'm trying to use this code to save to my access database and although there are no errors and it says data saved, my access database doesn't receive the new data. What's wrong with it?
Private Sub savenew()
Dim conn As New OleDbConnection
conn = New OleDbConnection
dbprovider = "Provider=Microsoft.ACE.OLEDB.12.0;"
dbsource = "Data Source = FULL YUGIOH ACCESS DATABASE.accdb;"
conn.ConnectionString = dbprovider & dbsource
Dim reader As OleDbDataReader
Dim command As OleDbCommand
Try
conn.Open()
Dim query As String
query = "insert into item(name) values ('" & TextBox4.Text & "')"
command = New OleDbCommand(query, conn)
reader = command.ExecuteReader
MsgBox("data saved")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
(table in my database is called item, and column is called name.)

Visual Basic using Visual Studio 2012 with Access! Can't get image url's to load into picture box

I am currently learning VB and my task is to do a quiz that stores details of the user and also stores the questions and answers. The problem I'm having is that I've stored URL's in the database but I'm unable to turn these into the actual images using the picturebox tool.
Here is my code to do this:
Dim con As New OleDb.OleDbConnection
Dim dbprovider As String
Dim ds As New DataSet
Dim dbsource As String
Dim sql As String
Dim da As OleDb.OleDbDataAdapter
dbprovider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbsource = "Data Source = C:\Users\kiera\Desktop\Assignment2.mdb"
con.ConnectionString = dbprovider & dbsource
con.Open()
MsgBox("open")
sql = "Select * from questions_new Where ID = 1"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Question")
For Each row As DataRow In ds.Tables("Question").Rows
Label1.Text = (row.Item("Question"))
Label2.Text = (row.Item("Answer_1"))
Label3.Text = (row.Item("Answer_2"))
Label4.Text = (row.Item("Answer_3"))
Label5.Text = (row.Item("Answer_4"))
PictureBox1.Image = (row.Item("Img"))
Next row
' con.Close()
'MsgBox("closed")
End Sub
The issue is that PictureBox1.Image has a type of System.Drawing.Image.
The property that you want is PictureBox1.ImageLocation which is a string that can be a local path or a URL.

need help connecting ms access to vb.net

I need help my program don't the use connection string that i want instead it find the access file on this folder and display error
Could not find file 'C:\Users\user\Documents\Visual Studio 2008\Projects\Patientt\Patientt\bin\Debug\db_hospital.accdb'.
here is my code
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\db_hospital.accdb"
con.Open()
sql = "SELECT * FROM tblPatients"
ds.Clear()
da = New OleDbDataAdapter(sql, con)
da.Fill(ds)
Me.DataGridView1.DataSource = ds.Tables(0)
con.Close()
Put your access file in the debug folder and change the connection string like this
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\\db_hospital.accdb"

Exception OLEDB in vb.net when connecting with MS Access

When i type
"dbProvider = "provider=microsoft.ace.oledb.12.0;"
dbSource = "data source = d:/data1.accdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "select * from table 1"
da = New OleDb.OleDbDataAdapter(sql, con)
MsgBox("database is now open")
da.Fill(ds, "ohr id/phr id")
con.Close()
MsgBox("database is now closed")"
However when i type the following code with a change in the sql query. It shows OLEDB Exception occurs.
"dbProvider = "provider=microsoft.ace.oledb.12.0;"
dbSource = "data source = d:/data1.accdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
sql = "select column 1 from table 1"
da = New OleDb.OleDbDataAdapter(sql, con)
MsgBox("database is now open")
da.Fill(ds, "ohr id/phr id")
con.Close()
MsgBox("database is now closed")"
Please tell me what is going wrong?. Thanks in advance
P.S.:the code waroks fine till MsgBox("database is now open")...the problem appears only in da.Fill(ds,"...")

connecting a visual basic 2008 express program to microsoft access 2003 in 64 bit operating system

I am working on an experimental project and have run into a problem trying to connect a microsoft access database to my program in visual basic 2008 express and keep getting the following message when I try to make the connection.
"The 'Microsoft.Jet.OLEDB.4.0C:\Users\lewis\Documents\programming\programs\cadet stores program\squadron stores system V1.1\squadron stores system V1.1\stores database\213 squadron stores.mdb' provider is not registered on the local machine."
After some research I have seen that there may be an issue because I am using a 64 bit operating system with 32 bit software. Any help or suggestions I would be grateful
This is the method I am currently trying to use:
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
dbProvider = "Provider=Microsoft.Jet.OLEDB.4.0"
dbSource = "C:\Users\lewis\Documents\programming\programs\cadet stores program\squadron stores system V1.1\squadron stores system V1.1\stores database\213 squadron stores.mdb"
con.ConnectionString = dbProvider And dbSource
con.Open()
I have now re written the syntax as shown bellow:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As New OleDb.OleDbConnection
Dim connString As String
connString = "Provider = Microsoft.Jet.OLEDB.4.0;"
connString &= "C:\Users\lewis\Documents\programming\programs\cadet stores program\squadron stores system V1.1\squadron stores system V1.1\stores database\213 squadron stores.mdb;"
con.ConnectionString = connString
con.Open()
MessageBox.Show("Conection open")
End Sub
However I now get the following error message:
"Format of the initialization string does not conform to specification starting at index 35."
The connection now works many thanks for your help
many thanks
Lewis
This is just wrong:
' And does not concatenate strings
con.ConnectionString = dbProvider And dbSource
what you probably meant was:
con.ConnectionString = dbProvider & ";" & dbSource
or
connString = "Provider=Microsoft.Jet.OLEDB.4.0; " ' end with a ;
connString &= "Data Source = C:\Users\lewis..."
con.ConnectionString = connString
I am using a 64 bit operating system with 32 bit software If this means your project is 32 bit, you shouldn't have a problem, but for info on using OLEDb 4.0 in 64bit mode look here