DataRowCollection.Remove and DataSet.HasChanges, bug???

W

W.G. Ryan MVP

John:

If I understand you correctly, the problem is that you have changes present
outside of the Removed row. It isn't what's causing HasChanges to return
true.. If you look at this code:
DataSet ds = new DataSet("CuckooDataSet");

ds.Namespace = "BillRyan";


DataTable dt = new DataTable("CuckooTable");

DataColumn dc = new DataColumn("CuckooName", typeof(System.String));

dt.Columns.Add(dc);

ds.Tables.Add(dt);

DataRow dro = dt.NewRow();

dro[0] = "BillRyan";

dt.Rows.Add(dro);

ds.AcceptChanges();

dt.Rows.Remove(dro);

Debug.Assert(!ds.HasChanges(), "There are changes present");



The assertion passes. Now, I know you said you didn't want to call
AcceptChanges but the reason the assertion passes is that prior to calling
AcceptChanges, there were changes present. Remove takes the value from the
collection. If instead we called Delete, then the assertion would fail. You
can call AcceptChanges on the specific row if you use Delete (but not
remove since remove gets rid of the row while delete merely changes the
rowstate)... this will leave the rest of the dataset in tact and get you
where you want to be.

So the reason it's returning true is because there are other changes
present, other than the ones in the row you're trying to remove. As such,
I'd .Delete it instead of .Remove it and then call AcceptChanges on that row
alone (or, perhaps call it on only the Deleted rows if you want rid of all
of them). If this won't work for you, please let me know a little more
about it and I'll see what I can do.


Cheers,


Bill
 

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