PC Review


Reply
Thread Tools Rate Thread

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

 
 
=?Utf-8?B?Sm9obiBSdXNr?=
Guest
Posts: n/a
 
      20th Jul 2005
Hi,

I'm calling table.Rows.Remove(row) to remove a row from a data table. But,
DataSet.HasChanges() still returns true.

Is there any way to make the row go away completely? (Without calling
AcceptChanges on the dataset or data table. I want to avoid that for the
reasons noted here:
http://weblogs.asp.net/grobinson/arc...02/146894.aspx )

John
 
Reply With Quote
 
 
 
 
W.G. Ryan MVP
Guest
Posts: n/a
 
      21st Jul 2005
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

"John Rusk" <(E-Mail Removed)> wrote in message
news:C3E5FE13-D953-457C-897C-(E-Mail Removed)...
> Hi,
>
> I'm calling table.Rows.Remove(row) to remove a row from a data table.
> But,
> DataSet.HasChanges() still returns true.
>
> Is there any way to make the row go away completely? (Without calling
> AcceptChanges on the dataset or data table. I want to avoid that for the
> reasons noted here:
> http://weblogs.asp.net/grobinson/arc...02/146894.aspx )
>
> John



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dataset HasChanges function not true when Dataset is passed as variable darjonase@gmail.com Microsoft VB .NET 7 27th Jun 2006 07:48 AM
DataSet.HasChanges = True after DataSet Loaded =?Utf-8?B?QXNwbm90?= Microsoft Dot NET Framework Forms 1 26th Sep 2005 09:04 PM
creating dataset from datarowcollection Matt Tapia Microsoft ASP .NET 0 3rd Nov 2004 08:59 PM
dataSet.HasChanges returns false after dataSet is modified pplppp Microsoft ADO .NET 4 24th Oct 2003 05:26 AM
Re: DataSet.Merge: DataSet.HasChanges returns true Markus Wildgruber Microsoft ADO .NET 6 4th Sep 2003 01:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:54 AM.