Nicolas78
Nicolas78

Reputation: 5144

Storing DataRows independently of a DataTable - RowNotInTableException

I'm creating a HashMap mapping the ID field of a row in a DataTable to the row itself, to improve lookup time for some frequently accessed tables. Now, from time to time, I'm getting the RowNotInTableException:

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

After looking around the net a bit, it seems that DataRows don't like not being attached to a DataTable. Even though the DataTable stays in memory (not sure if the DataRows keep a reference to it, but I'm definitely still caching it anyway), is it possible I'm breaking something by keeping those rows all isolated in a HashMap? What other reason can there be for this error? This post RowNotInTableException when accessing second time discusses a similar problem but there's no solution either.

UPDATE

I'm actually storing DataRowViews if that makes any difference.

Upvotes: 2

Views: 8253

Answers (1)

TcKs
TcKs

Reputation: 26642

The DataRow should be always attached to some DataTable. Even if is removed from DataTable, the row still has reference to the table.

The reason is, the schema of table is placed in DataTable not in DataRow (and the data itself too).

If you want fast lookup without DataTables, use some own structure instead of DataRow.

Upvotes: 3

Related Questions