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.