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"
Related
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.)
I am facing a problem that when i make the setup file of my application developed in vb.net the database file will not be attached to it, as a solution i wish to create the database # first run of the application through the following code
Dim myCommand As String
Dim myConnectionString As SqlConnection = New SqlConnection("Data Source=(local)\SQLEXPRESS;Initial Catalog=soft_billing;Integrated Security=True;Pooling=False")
myCommand = "CREATE database soft_billing"
Dim cmd As SqlCommand = New SqlCommand(myCommand, myConnectionString)
Try
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
Catch
MsgBox(" Already installed database", MsgBoxStyle.Critical, " MaS InfoTech- Warning")
End Try
it will not generated the required data base,
help me please, thanks in advane
Dim myCommand As String
Dim myConnectionString As SqlConnection = New SqlConnection("Data Source=(local)\SQLEXPRESS;Initial Catalog=master;Integrated Security=True;Pooling=False")
myCommand = "CREATE database soft_billing"
Dim cmd As SqlCommand = New SqlCommand(myCommand, myConnectionString)
Try
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
Catch
MsgBox(" Already installed database", MsgBoxStyle.Critical, " MaS InfoTech- Warning")
End Try
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")
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,"...")
I have this code that populates a datagridview with data from ms access:
Dim con As New OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim Sql As String
Sql = "SELECT * FROM myTable WHERE case_no=?"
Try
con.ConnectionString = "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=Sample.accdb;Persist Security Info=True;Jet OLEDB:Database Password=dbadmin2010"
con.Open()
Dim cmd As OleDbCommand = New OleDbCommand(Sql, con)
da.SelectCommand = cmd
cmd.Parameters.AddWithValue("case_no", case_no)
Dim ds As DataSet = New DataSet
da.Fill(ds, "Case Info")
DataGridView1.DataSource = ds.Tables("Case Info")
Catch ex As Exception
MsgBox(ex.Message)
End Try
Now I had just finished creating a query from design view within MS Access itself, is there a way to call that query and retrieve the results to my datagridview?
Just use the query name and set the command type, for example, in addition to what you already have, you can use the following notes:
Try
con.ConnectionString = enter_connection_string_here
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "NameOfQuery"
da.SelectCommand = cmd
cmd.Parameters.AddWithValue("case_no", case_no)
da.Fill(ds, "Case Info")