By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,606 Members | 2,019 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,606 IT Pros & Developers. It's quick & easy.

Windows Form Application : Save the Contents then close

P: 19
Hello,
i make some changes in my windows form applications and commit to save it in my database. However if the commit has not yet taken place.i would like to have an alert box with states if the user wants to quit without saving "yes" or "no".
however i do not know how to implement this. espiacially to check if the commit has taken place or no?

would be gratefull for any suggestion
Jul 29 '08 #1
Share this Question
Share on Google+
6 Replies


Plater
Expert 5K+
P: 7,872
If anything on the form has been changed since the last time the data was saved, set a boolean to false.
Then check for it on exit?
Jul 29 '08 #2

10K+
P: 13,264
If anything on the form has been changed since the last time the data was saved, set a boolean to false.
Then check for it on exit?
That would require a check for every keypress e.t.c on the windows. I'd rather do the check against the database just before exit only. If there is anything on the window that is different from what's in the database then ask for confirmation.
Jul 29 '08 #3

TTCEric
P: 26
That would require a check for every keypress e.t.c on the windows. I'd rather do the check against the database just before exit only. If there is anything on the window that is different from what's in the database then ask for confirmation.
This would be my approach (it avoids the back/forth trips to the database).

1. Create a function that creates a string containing the values in your controls. For example, it creates one huge string of control values.

2. Get the result of the function just after loading the database values. Throw it in a global variable.

3. Before exiting, make another call to the function but this time do a string comparison against the functions returned value and your global string variable. If they dont match, they haven't saved.

Of course, this assumes no one changes database values besides the user using your app. It wont be ideal if you also need to check changes other users may have made.
Jul 29 '08 #4

10K+
P: 13,264
More or less what I suggested above without representing all the values as one string though.
Jul 29 '08 #5

TTCEric
P: 26
More or less what I suggested above without representing all the values as one string though.
I find string comparisons very fast so I try to do alot of operations with them.
Jul 29 '08 #6

P: 19
thank u ..i solved it with the help of boolean values.. thanx a lot
Aug 8 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.