Detecting user changes to data on form

I have a form which is used to make changes to a database.

When the form first opens the form fields are populated from the database. How can I tell if the user changes any of the fields. I would like to be able to detect this so that if the user tries to close the form I can prompt them to see if they wish to save the changes.

Thanks

[341 byte] By [CarlInMilford] at [2007-12-17]
# 1

Hi Carl,

you can use the HasChanges method of the DataSet or the GetChanges method of the DataTable objects.

For example:

If (myDataSet.HasChanges) Then
' Prompt user here
End If

Or for a typed dataset you can do

If (myDataSet.MyTable.GetChanges() IsNot Nothing) Then
' Prompt user here
End If

After you prompt the user, if the user answers 'yes' to save the changes, you can use the DataAdapters to send the changes back to the database.

HTH

Antoine
Visual Basic team

Antoine_MS at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2

I had to add an EndEdit() as below to get it to work. Is that the right thing to do? Individual is the table.

Me.IndividualBindingSource.EndEdit()

If Me.VBNMDATADataSet.Individual.GetChanges() IsNot Nothing Then MessageBox.Show("Changes")

GS

GS at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3
Yes, that tells the binding manager to make sure to push current edits to the underlying dataset.

Antoine
Visual Basic team

Antoine_MS at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...