I am connecting an access mdb format and cannot display the values from the database table onto a form in vb . I need also to enter values to the same database. I appreciate any help anyone can provide as I am new to all this. I did the same exercise as from http://www.homeandlearn.co.uk/NET/nets12p4.html
but did not help a lot.

Dani AI

Generated

For : the usual causes when an Access file will not show or save data are a provider/format mismatch, an incorrect path or file-permissions issue, or a runtime bitness mismatch. was right to point toward the driver — the next useful steps are a short checklist and a minimal read/write pattern you can try.

Checklist

  • Confirm which Access engine your file needs (older MDB uses Jet, newer formats use ACE) and make sure that engine is installed on the machine running the app.
  • Use a full filesystem path in the connection string (not just the filename).
  • If running on a 64-bit OS, build the app for x86 in VS2005 to avoid 64/32-bit provider problems.
  • Ensure the account running the app (or the ASP.NET worker) has read/write permission to the .mdb and the file is not opened exclusively in Access.

Sample read-and-bind (WinForms)

Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\path\MyDb.mdb;Persist Security Info=False;"
Dim sql As String = "SELECT * FROM MyTable"
Dim dt As New DataTable()

Using cn As New OleDb.OleDbConnection(connString)
  Using da As New OleDb.OleDbDataAdapter(sql, cn)
    da.Fill(dt)
  End Using
End Using

DataGridView1.DataSource = dt

Sample parameterized insert

Dim insertSql As String = "INSERT INTO MyTable (Col1, Col2) VALUES (?, ?)"
Using cn As New OleDb.OleDbConnection(connString)
  Using cmd As New OleDb.OleDbCommand(insertSql, cn)
    cmd.Parameters.AddWithValue("?", TextBox1.Text)
    cmd.Parameters.AddWithValue("?", TextBox2.Text)
    cn.Open()
    cmd.ExecuteNonQuery()
  End Using
End Using

Troubleshooting tips

  • Read and paste exact exception messages into search results; common messages map quickly to the checklist items above.
  • For data edits, either call ExecuteNonQuery for explicit INSERT/UPDATE/DELETE or use an OleDbDataAdapter with an OleDbCommandBuilder and call Update on the DataTable.
  • If you need reference connection-string examples, see the Access collection at Access connection strings.

Recommended Answers

All 3 Replies

what version of MS Access you are using?

what version of MS Access you are using?

Access 2007 in windows vista and in saved as mdb format

Thank you

Access 2007 in windows vista and in saved as mdb format

Thank you

that's not correct extention. The MS Access 2007 has .accdb extention.

Example, you created a database using Access 2007 "myDataBase.accdb"

So in your connection string it should looked like:

Dim conn As New Oledb.OledbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Datasource=myDataBase;Persist Security Info=False")
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.