Windows Form BindingSource not saving changes in database
-
Update: This did turn out to be a pretty simple issue, so I am marking it now as an Answer. See the end of the message for the Answer... I suspect I am making a very simple error, because I have a Windows Form application where I have added an Entity Framework DataSource bound to controls via a BindingSource/BindingNavigator that is not saving changes to the underlying SQL database. I started by dragging the Entity Framework DataSource (as Details) onto a form. This automatically created the form controls, the BindingSource and BindingNavigator. When I first brought up the form, no records where being returned from the Entity Framework DataSource, so I created the following variable to initially load data that I was then able to view:
Private TblList As ObjectQuery(Of tblMyTableRec) = From tbl In ObjCntxt.tblMyTableRecs
Then I set the DataSource property of the appropriate BindingSource to this ObjectQuery:
MyBindingSource.DataSource = TblList
So far, so good ... The BindingNavigator now lets me move through the various records in the 'tblMyTableRecs' table. But, when I make a modification of the data in any of the records (via one of the data bound controls), my changes are not being saved to the underlying SQL database the Entity Framework is setup to use. I would greatly appreciate any suggestions about what steps I might need to take so that I am able to have changes saved in my SQL database. Answer: The code generated for the Windows Form BindingSource and BindingNavigator do not automatically perform the Entity Framework ObjectContext SaveChanges operation. Once the SaveChanges function was executed in the Save button Event logic for the appropriate Entity Framework ObjectContext, the changes were saved to the SQL database.
Thanks, Dean