Datarow delete- Implicit AccpetChanges on certain datasets

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)
 
M

Miha Markic [MVP C#]

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
 
C

Cor Ligthert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top