Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Gents,
Each time I edit the details in my database such as (delete, add) it works perfectly when I view the access database but does not update the data in my datagridview except I close the program and re-open it. Is there a way I can refresh the datagridview so that it updates itself automatically. I use microsoft access 2007 as my database.

Below is the code I have so far:
Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click
      If InspDataGridView.SelectedRows.Count <> 0 And lblInsSheet2Edit.Text = "QuarryMech" Then
                Dim James As String
                James = MsgBox("Confirm this inspection has been completed", MsgBoxStyle.YesNo, "EwekoroII Inspections Tracker")
                If James = vbYes And lblWhoLogged.Text = lblInsSheet2Edit.Text Then
                    Dim agreement As OleDb.OleDbConnection
                    Dim dldb, myguy As String
                    
myguy = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Methods Inspections.mdb")

                    agreement = New OleDb.OleDbConnection(myguy)
                    agreement.Open()

dldb = "UPDATE QuarryMech SET Status = '" & "Done" & "' WHERE Ins_Date = '" & lblReturnedDate.Text & "' AND Inspection = '" & lblReturnedInspection.Text & "'"

                    Dim halt = New OleDb.OleDbCommand

                    Try
                        halt = New OleDbCommand(dldb, agreement)
                        halt.ExecuteNonQuery()
                        InspDataGridView.RefreshEdit()

                        Catch ex As Exception
                        MsgBox(ex.Message, MsgBoxStyle.Critical, "Oledb Error")
                    End Try
                End If
Posted
Updated 25-Sep-13 4:45am
v2
Comments
Richard C Bishop 25-Sep-13 10:46am    
If you do not set the datasource, your datagridview will not refresh. Are you doing that at some point?

1 solution

Hello,

The best way to update the datagridview is using DataSets. You can create a dataset with the wizard. The wizard create TableAdapters for each table of the database.

After that, you can update the datarid easier.

Example:

C#
MyDataSetTableAdapters.MyTableTableAdapter ta = new MyDataSetTableAdapters.MyTableTableAdapter();
ta.Fill(myDataSet.MyTable);


With this method you can obtain the last result from your database all times you need.

I do recommend that you take a interviewee to the documentation of microsoft ado.net concerning.

http://msdn.microsoft.com/en-us/library/e80y5yhx.aspx[^]
 
Share this answer
 
Comments
ridoy 25-Sep-13 12:19pm    
5ed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900