is that safe to say a Detached DataRow neve in a DataTable's Rows collectoin? Error due to multiple

R

Ryan Liu

Hi,

Is that safe to say a Detached DataRow neve in a DataTable's Rows
collectoin?

But in my log file, I do see a Detached row:

foreach(DataRow dr in this.currentQuotaUserDt.Rows)
{

object temp = dr[quotaId.ToString()];
.....
}

throws exception : This row has been removed from a table and does not have
any data. BeginEdit() will allow creation of new data in this row.

So maybe this exception is caused by multiple threading, the statement I
made is still right?

Thanks a lot!
Ryan
 
G

Guest

Ryan,
Sahil Malik cleared this up very nicely in a blog post:

"When you call NewRow on a table - only the rowstate is detached. There is
private variable inside of DataRow called as _Table, which is populated by
the table instance that NewRow was called upon.

How it got the instance was - datatable stores an instance of an internal
class called DataRowBuilder, and DataRowBuilder.Table = this (the table
itself). DataRowBuilder - is what is used to generate the new row for you.

Soon as you did an Add to the rows collection, the rowstate was changed from
Detached to <<non-detached>> something else, in which case the dataadapter
will now pick it."

Hope that helps out.
Peter
 

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