views:

256

answers:

3

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?

+1  A: 

I would say that the way you are currently doing it is fine. If you start attempting to update the database while the user is still making edits you can run in to issues updating or modfiying things that the user may ultimately decide they did not want to change. Additionally this has the chance to greatly increase the number of database calls.

Forcing the user to click apply helps ensure that only the changes the user actually wants are sent to the database.

As for losing the changes if the app crashes before applying them, I would be more concernced with why the app is crashing.

cptScarlet
Thanks - I guess this is the best way.
Ezekiel Rage
A: 

Uhm, I guess this is the best way. Thanks.

Weeber
A: 

The only important thing to remember is that you should refetch the data before saving it and the refetched data should still match the data you originally displayed to the user. If it doesn't, someone else made a change your user will be unknowingly overwriting. Your users probably will not like that.

How you handle this is dependent on what your client needs in their database.

jmucchiello