Refresh the DataGridView after the data is inserted into the database by another dialog

In my Winforms application, I have a primary form with a DataGridView associated with a database Entity data source.

The mesh is set to not allow insertions. Instead, I have a button in my form that calls the second dialog in which the insert occurs (i.e. with a friendlier ui than is possible with a DataGridView).

The insert is working fine. Querying the base table in db indicates that the record has been inserted. However, I cannot get the DataGridView to see the new data created in the second dialog box in its primary form.

I read a lot of qaru q and a and tried various solutions to update the DataGridView to show new data .. but nothing works.

Should this be a normal situation? Can someone suggest some VB.NET code that will work?

Thanks,

Bazza

Dim qry = From o In mDB.tblFOMTestResults From p In mDB.tblProduct.DefaultIfEmpty _ From c In mDB.tblCalibration _ Where o.ProductID = p.ID And o.CalibrationID = c.ID _ Order By o.RunDate, p.ProductName Select _ o.ID, o.SampleCode, o.RunDate, o.ConditioningDays, o.ConditioningRHAndTemp, _ o.TestArea, o.EdgeSeal, o.SealedBags, o.FaceSeal, _ o.MoisturePercentage, o.CalibrationID, o.FYFOMH1, o.FYFOMH2, o.FYFOMH3, _ o.FYFOMH4, p.ProductName, o.ProductID Me.TblFOMTestResultsDataGridView.DataSource = qry 
0
source share
2 answers

After several attempts, I finally got this, following the tips from the following SO answer .. Update a DataGridView on a Windows Form

0
source

Try to bind the query results, not the query:

 dataGridView.Source = query.Execute(MergeOption.AppendOnly); 
+1
source

All Articles