Pete
Pete

Reputation: 469

Is there a way to stop myDataSet.HasChanges() returning true if the only change is a new row?

I have a Button on my Form that when clicked calls myBindingSource.AddNew(). Controls relevant to setting the values on that new row then become visible.

On the close event of that Form i call myDataSet.HasChanges() and if it returns True, i prompt the User if they would like to save the changes they have made.

In the situation where the User clicks to add a new row but then closes the Form, (for whatever reason) without setting any values, myDataSet.HasChanges() will return True obviously because there is the adding of a new row.

What i would like is a way to make it return False if the only change is a new row.

I have tried calling myBindingSource.EndEdit() then myDataSet.AcceptChanges immediately after myBindingSource.AddNew() but myDataSet.HasChanges() still returns True.

I thought by calling myDataSet.AcceptChanges() it would essentially wipe the slate clean and only changes made after that point would be picked up.

Or alternatively if there is a better approach to this i would like to hear it.

I am keen on the idea of only saving back to the DataBase in one go when prompting to save, rather than inserting the new row on the Button.Click and updating that row on each value change.

Upvotes: 0

Views: 278

Answers (1)

jmcilhinney
jmcilhinney

Reputation: 54457

To be more specified than my comment:

If myDataSet.HasChanges(DataRowState.Deleted Or DataRowState.Modified) Then

Upvotes: 2

Related Questions