I have a database table that loads to a DataTable object which is binded to multiple UIElements such as DataGrid, ComboBox, TextBoxes etc’s ItemsSource property. Is there a way where I am implement a “watch dog” that constantly check if the DataTable or DataSet has been changed and automatically update the database on a separate thread?
My goal is to eliminate the need for the client having to manually trigger a “Save” event to propagate these changes to the database, and that the database is always in-sync with the data in DataSet/DataTable. Please also suggest if this is a good practice or is there a better alternative.
The DataTable object has many events that get triggered on row data change.
You could use RowChanged/RowChanging, RowDeleted/RowDeleting
See a full documentation on MSDN
You could add an event handler for a RowChanging event in this simple way
and then add the handler
where the Action property is an enum that describes the operation