Datarow delete- Implicit AccpetChanges on certain datasets

  • Thread starter Thread starter Matt
  • Start date Start date
M

Matt

I have seen this question posted before but never answered.

If I load a DataSet from a database query, I need to call
AcceptChanges after DataRow.Delete to remove rows.

If I load a DataSet from an XML file or create one from scratch
programatically- DataRow.Delete removes rows immediately, seemingly
bypassing the rowstate and implicitly calling AccpetChanges. This
happens on single table datasets, so it is not a constraint related
issue.

This behavior doesn't appear to be documented. Any explanations?

Thanks
(originally posted by Scott Allen)
 
Hi Matt,

Matt said:
I have seen this question posted before but never answered.

If I load a DataSet from a database query, I need to call
AcceptChanges after DataRow.Delete to remove rows.

No, you shouldn't call AcceptChanges.
You will reset the rowstate and Update won't work because it won't see which
row was deleted.
AcceptChanges resets row state to unmodified.
If I load a DataSet from an XML file or create one from scratch
programatically- DataRow.Delete removes rows immediately, seemingly
bypassing the rowstate and implicitly calling AccpetChanges. This
happens on single table datasets, so it is not a constraint related
issue.

Delete row either marks row as Deleted (a) or removes (b) the row .
a) when RowState is not Added
b) when RowState = Added
 
Matt,

In addition to Miha.

When you don't want to update with the dataset the database anymore. You can
of course than use the acceptchanges.

However for that you can than use as well the commands
datarowcollection.remove and (at)

That has direct the same effect as calling after the delete the
acceptchanges. It removes the row direct from the collection and therefore
the rowstate cannot by used anymore.

Just a little addition.

Cor
 
Back
Top