VB Code:
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If Me.DataSet1.HasChanges() Then
Select Case MessageBox.Show("Would you like to save the changes?", _
"Save Changes", _
MessageBoxButtons.YesNoCancel, _
MessageBoxIcon.Question)
Case Windows.Forms.DialogResult.Yes
'Save changes and allow the form to close.
Case Windows.Forms.DialogResult.No
'Allow the form to close without saving changes.
Case Windows.Forms.DialogResult.Cancel
'Do not save changes but do not allow the form to close.
e.Cancel = True
End Select
End If
End Sub
You would then have a separate method that actually saved the changes, which you could call from this event handler or anywhere else.