At what point to save data.

SteveInBeloit

Well-known member
Joined
May 22, 2006
Messages
132
Programming Experience
10+
Hi,
I am looking for some opinions here.

At what point do you want to persist data changes back to the server? I am coming from ACCESS where the data is changed when you leave the row.

I currently have a form with three DataGridViews on it. I don't really want to have three bindingNavigators and have them pushing the save button each time they do something on any of the three DGVs. Could you have one save button at the top and instruct them to push it, and the put the code behind it to save to all three, knowing they may not have changed all three?

Or do you put it on the close event of the form? Or should you put it in an event everytime they leave a row, that could be excessive for my project.

How do others do it?

Thanks
Steve
 
Only your users or you can say when to save changed data.
How precious is it? Can it be easily reentered if something
bad happens?
Maybe you can imitate transaction processing; a logical group of
changes is pending until the transaction is complete, then all
updates for that transaction are committed to the DB at one time.
The classic example: moving money from one bank account to another,
where both accounts must reflect the move simultaneously - if
either account update fails, the whole transaction is backed out,
and nothing is updated.
 
i have a DataAccess class that is used to work with Access databases and everytime something changes after data is retrieved the class automatically opens the DB, applies the changes and closes the DB.

this allows us to have 10 computers make changes to different records within 10 seconds of each other
 
Hi,
I am looking for some opinions here.

At what point do you want to persist data changes back to the server? I am coming from ACCESS where the data is changed when you leave the row.

I currently have a form with three DataGridViews on it. I don't really want to have three bindingNavigators and have them pushing the save button each time they do something on any of the three DGVs. Could you have one save button at the top and instruct them to push it, and the put the code behind it to save to all three, knowing they may not have changed all three?
Yes. Look at the default code for all the Save buttons.. now combine it into one, remembering that if there are parent child relationships, parents must be saved first and a transaction should be used

Or do you put it on the close event of the form?
No, i normally put a "If dataset.HasChanges Then MessageBox.Show(you have unsaved changes..)" in there

Or should you put it in an event everytime they leave a row, that could be excessive for my project.
The idea of offline data is that we dont go poking the database every time the user does something insignificant, but if the realtime uptodateness of your app is critical, then you will have to update at this granularity, or finer


How do others do it?
Depends on context. Usually a single save button which saves all, and a warning on unsaved changes
 
If I was going to have the changes persisted each time the user left the row, what event would I put the .Update in?
Code a generic event handler suitable for BindingSource.CurrentChanged and attach all your bindingsources to it and call all Update()s in it. Or code a separate handler for each and only call the relevant Update() in each
 
No, i normally put a "If dataset.HasChanges Then MessageBox.Show(you have unsaved changes..)" in there

Anyway to check this at the datatable level, I see it does not have a .hasChanges on it. Also, I see the actual form does not have a Closing event? I must be missing something there.


Code a generic event handler suitable for BindingSource.CurrentChanged and attach all your bindingsources to it and call all Update()s in it. Or code a separate handler for each and only call the relevant Update() in each

I'm looking now on how to do this, it sounds very useful.
 
Code a generic event handler suitable for BindingSource.CurrentChanged and attach all your bindingsources to it and call all Update()s in it. Or code a separate handler for each and only call the relevant Update() in each

Man, this fires a lot of times. Once per row just opening the form. Is there a better event to put the .Updates in?
 
Back
Top