I have a datacentric windows forms application performing CRUD functions to a database with 3 tables: rcTable (real estate); scTable (different real estate); and imgTable (pictures of both types of real estate). Data entry forms were designed using the windows forms designer and VB code-behind has been extensively modified with Linq-enabled VB code for data validation and manipulation.
The problem I am having is that my datagridview controls throughout the application do not reliably update to reflect records which have been manually inserted and deleted via the Linq datacontext. If I exit and re-run the application, the changes show up in the datagridview controls.
I suspect that I have some inconsistency in the databinding of my controls between the Linq and ado.net objects. In this regard I have several questions regarding how databinding should happen, how insert/delete and methods should be wired, and how/whether the ado.net and Linq dataset objects should coexist.
First of all, the forms designer automatically inserts code like the following in my forms where I have defined a dataset connection:
'TODO: This line of code loads data into the 'REdataDataSet.PropImages' table. You can move, or remove it, as needed.
'Me.PropImagesTableAdapter.Fill(Me.REdataDataSet.PropImages)
Can this code be deleted?
I have also used the forms designer to put a binding navigator on my forms. Should the binding navigator's add/delete/change hooks be wired to the linq objects or the ado.net table adapter? Or does it matter?
Because I am trying to use Linq to SQL for all of my data manipulation, I also have something like the following in the declarations region of my forms modules:
Private db As New DataContext(myConfig.dbActive)
Private imgTbl As Table(Of PropImage) = db.GetTable(Of PropImage)()
Private rcTbl As Table(Of RentComp) = db.GetTable(Of RentComp)()
Private scTbl As Table(Of SaleComp) = db.GetTable(Of SaleComp)()
Clearly, this creates Linq table objects for use within the form module, but does it also create duplicate and possibly inconsistent Linq objects in other form modules? For data inserts, deletes, and changes I assume I should be using InsertOnSubmit/DeleteOnSubmit on the Linq table objects, SubmitChanges to the in-memory datacontext, but how/when are the disk-images of the tables and database updated? Is this automatic or do I need to do anything else?
Instead of the inital assignment statements in the declarations section, should I have a refresh method that I can call after any data changes? Maybe something like the following:
Private Sub dbReBind()
db.Refresh(RefreshMode.OverwriteCurrentValues)
imgTbl = db.GetTable(Of PropImage)()
rcTbl = db.GetTable(Of RentComp)()
scTbl = db.GetTable(Of SaleComp)()
End Sub 're-bind datacontext elements
What about controls which may be mistakenly databound to ado.net dataset objects? Are these automatically updated when the database is updated? Do I need to do anything to implement iNotifyPropertyChanged? If so, how or where does this code go? I would like for my databound controls to be automatically updated in the simplest manner.
Any specific help or references to understandable resources would be appreciated.
Thanks,
-BGood