PC Review


Reply
Thread Tools Rate Thread

detached rows in DataTable

 
 
jurson
Guest
Posts: n/a
 
      7th Feb 2005
Hello,

I remove row from DataTable. It works ok, the row is removed from
collection. It should be marked as 'detached'. Am I right?

Then I try to retrieve 'detached' rows using the code shown below.
_currentEntryBE.Tables["EntryList"].Rows.Remove(dr);

DataTable dt =
_currentEntryBE.Tables["EntryList"].GetChanges(System.Data.DataRowState.Detached);


I always get "null".

Is there any other way to retrieve 'detached' rows from DataTable.

jurson
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      7th Feb 2005
Jurson,

With remove it is removed. When you want a previous readed row to be marked,
you should use delete.

http://msdn.microsoft.com/library/de...eletetopic.asp


I hope this helps?

Cor


 
Reply With Quote
 
jurson
Guest
Posts: n/a
 
      7th Feb 2005
Cor Ligthert,

Thanks for answer. Unfortunatelly I can't use Delete() for some reason.

According to
http://msdn.microsoft.com/library/de...classtopic.asp

'detached' state is described:
'The row has been created but is not part of any DataRowCollection. A
DataRow is in this state immediately after it has been created and
before it is added to a collection, or if it has been removed from a
collection.'

jurson

 
Reply With Quote
 
jurson
Guest
Posts: n/a
 
      7th Feb 2005
Cor,

I decide to follow Your advice.

I have just rewritten my code to be able to use Delete(). I couldn't
find a method to reach 'detached' rows.

thanks,
jurson
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      7th Feb 2005
Jurson,

I never tried it, however I think that as you use something as

DataRow dr = ds.Tables[0].Rows[0];
ds.Tables[0].Rows.Remove(dr);

That you than still can get dr

However as I said I did not try it.

Cor


 
Reply With Quote
 
Alex
Guest
Posts: n/a
 
      7th Feb 2005
Hi Jurson.

The GetChanges() Method of the DataTable iterates through all rows of
the DataTable. Since you have used DataTable.Remove(dr); there are no
rows in the collection and GetChanges() returns null.

You should use the Deleted() method of the row instead, as Cor already
said. This is because the row will only be marked as deleted, but not
removed immediately. In fact, it will be removed from the collection as
soon as you call DataTable.AcceptChanges();

DataRow.Remove(); will call AcceptChanges() for this row and will not
add itself to the deleted rows collection of the Table.

If you remove a row and you have a reference to it, you can get the
RowState, which will be *detached*.


dt.Rows.Remove(dr);
dr.RowState <- this will be detached.
but dr will no longer be in dt.

Kind regards
Alex

- Alexander Rauser

http://www.flashshop.info

jurson wrote:
> Hello,
>
> I remove row from DataTable. It works ok, the row is removed from
> collection. It should be marked as 'detached'. Am I right?
>
> Then I try to retrieve 'detached' rows using the code shown below.
> _currentEntryBE.Tables["EntryList"].Rows.Remove(dr);
>
> DataTable dt =
> _currentEntryBE.Tables["EntryList"].GetChanges(System.Data.DataRowState.Detached);
>
>
> I always get "null".
>
> Is there any other way to retrieve 'detached' rows from DataTable.
>
> jurson

 
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
Cannot remove a detached row from a DataTable Hamed Microsoft Dot NET 2 14th Feb 2007 08:59 AM
Cannot remove a detached row from a DataTable Hamed Microsoft C# .NET 3 14th Feb 2007 08:59 AM
Cannot remove a detached row from a DataTable Hamed Microsoft ADO .NET 3 14th Feb 2007 08:59 AM
is that safe to say a Detached DataRow neve in a DataTable's Rows collectoin? Error due to multiple threading? Ryan Liu Microsoft C# .NET 1 30th Jul 2006 07:41 PM
Detached rows in a datatable Peter Borremans Microsoft ADO .NET 9 19th Mar 2004 01:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:35 AM.