Member Avatar

Hi, need some help.

How can I retrieve data from MS Access database into DataGridView that allow me to ADD/UPDATE/SAVE/DELETE? Thanks.

Hope someone can help me.


Can you post the code you have so far? I'd also google and run a search on this very forum - they have loads of examples and queries on here about datagridviews

You can use below code:

'connect with database
Dim connection As New OleDbConnection()
connection.ConnectionString = "Provider=""Microsoft.Jet.OLEDB.4.0"";Data Source=""demo.mdb"";User Id=;Password="
Dim command As New OleDbCommand()
command.CommandText = "select * from parts"
Dim dataSet As DataSet = New System.Data.DataSet()
Dim dataAdapter As New OleDbDataAdapter(command.CommandText, connection)
Dim dt As DataTable = dataSet.Tables(0)
Me.dataGridView1.DataSource = dt

Details can be seen in the last solution of this article:
Solutions to Export Data From Database to Excel in C#

Getting Error at dataadapter.fill(Dataset)

            Dim con As New OleDbConnection
            con.ConnectionString =      "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =databasename.accdb"
            Dim cmd As New OleDbCommand
            cmd.Connection = con
            cmd.CommandText = "select * from Assets "
            Dim da As New OleDbDataAdapter
            Dim ds As New DataSet
            da.SelectCommand = cmd
            Dim cb As New OleDbCommandBuilder
            cb.DataAdapter = da
            da.Fill(ds, "Assets ")
            DataGridView1.DataSource = ds.Tables("Assets ")

try this one !!!!