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.

Lejan
Deleted Member

Hi,

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)
dataAdapter.Fill(dataSet)
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#

            Dim con As New OleDbConnection
            con.ConnectionString =      "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =databasename.accdb"
            con.Open()
            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 ")
            con.Close()

try this one !!!!

This article has been dead for over six months. Start a new discussion instead.