Help with Datagrid and Access Database

Basicfarmer
Basicfarmer used Ask the Experts™
on
Experts would someone please show me an example of how to use my datagrid with my access database so that when I make changes to the data grid those changes are reflected in the database?

Below is how i am filling the datagrid.
The SQL query is passed as an argument to my procedure because I have a search function so the user can search the records. When the user presses the search button the query is built and passed to the fillEquipment procedure which displays the records in the datagrid. When the form loads the the procedure is called like fillEquipment("SELECT * FROM Equipment").

    Public Sub fillEquipment(strSql As String)

        Dim da As New OleDbDataAdapter(strSql, con)
        Dim dt As New DataTable
        da = New OleDbDataAdapter(strSql, con)
        da.Fill(dt)
        DataGridView1.DataSource = dt
        
    End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Microsoft ISV Partner
Commented:
Let me introduce you to Code On Time from
https://codeontime.com/
They have a free standard tool for autogenerating all the datagrids you need from your Access DB. Very easy to use and you can copy all the code you need from the generation and reuse it in your program if you like.
The .Fill method loads data from the database into the datatable. You need to do a .Update to return the data from the datatable back to the database. So somewhere you need to have a

da.Update(dt)

which gets executed after you've made the changes to the datagrid.

Author

Commented:
Thanks for the great tips guys...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial