detached rows in DataTable

J

jurson

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
 
J

jurson

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
 
C

Cor Ligthert

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
 
A

Alex

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
 

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