Member Avatar for Lejan

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.

Recommended Answers

All 5 Replies

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#

Getting Error at dataadapter.fill(Dataset)

What is the error ?

            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 !!!!

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.