Synchronizing DataGridView (DataTable) with the DB

Posted by Ezekiel Rage on Stack Overflow See other posts from Stack Overflow or by Ezekiel Rage
Published on 2009-08-17T13:12:14Z Indexed on 2010/06/07 20:22 UTC
Read the original article Hit count: 272

Hi!

I have the following situation: there is a table in the DB that is queried when the form loads and the retrieved data is filled into a DataGridView via the DataTable underneath. After the data is loaded the user is free to modify the data (add / delete rows, modify entries).

The form has 2 buttons: Apply and Refresh. The first one sends the changes to the database, the second one re-reads the data from the DB and erases any changes that have been made by the user.

My question is: is this the best way to keep a DataGridView synchronized with the DB (from a users point of view)?

For now these are the downsides:

  1. the user must keep track of what he is doing and must press the button every while
  2. the modifications are lost if the form is closed / app crash / ...

I tried sending the changes to the DB on CellEndEdit event but then the user also needs some Undo/Redo functionality and that is ... well ... a different story.

So, any suggestions?

© Stack Overflow or respective owner

Related posts about c++

Related posts about database