I have a small issue that I am unable to figure out. I have a form in my application called FORM1. On button click SEARCH - i show user data in a DATAGRIDVIEW. So now that I have data - user has the option to add a new client, so they click a button and I have a new form that pops up. I do not close FORM1 - i leave it as it and create a new child like this....
Dim NewMDIChild As New frmNewClient()
NewMDIChild.MdiParent = MDIContainer
It sounds like you are looking for a way for one form to know that another has made db changes. Given a form to add or edit a row, you can invoke a method whenever another form adds/changes or deletes a row:
Public Sub SampleDSChanged() daSample.Fill(dtSample) ' refresh dgv1.FirstDisplayedScrollingRowIndex = dgv1.RowCount - 1 End Sub
On the form to add/edit a record:
dbcon.Open() Dim rows = cmd.ExecuteNonQuery() If rows > 0 Then frmMain.SampleDSChanged() End If
The Edit/New form, INSERTS or UPDATES records as needed using its own SQL statements, acting directly on the db. Afterwards, the method just acts as a notifier. Result:
The 'baby form' is able to add or edit records, in either case it 'tells' the main form that it has done so. The
DataGridView is just showing that it gets the notice, it may not actually exist.
Even if you are writing old school form-centric apps, you can leverage the capabilities of the NET provider. Namely, different actors (forms) can make changes to a single datasource so any changes are immediately visible to all concerned parties. You just need to make some of the data objects available.
Even using the same form for ADD and EDIT and an UPSERT method, there is about five times more code involved in having the Edit/Add form act independently than working with a common datasource.