DataTable - the order of rows.

  • Thread starter Thread starter Dobieslaw Wroblewski
  • Start date Start date
D

Dobieslaw Wroblewski

Hello,

I am adding rows to the data table without primary key defined using the
DataRowCollection.Add(object[]) method.

When I am reading the table directly or using its default view or a view
with order set to "", I would like to process the records exactly in the
order in which they were added.

The question is whether I can trust the actual order of rows or it might be
implementation-dependent?

DW.
 
You can trust the order of the rows inserted into the DataTable if you
iterate
through the DataRowCollection of the DataTable when you go to read the
table.
There is no need to use a View unless you want to perform sorting,
filtering, or
querying on the DataTable.

-Darren Shaffer
 
Thanks for the answer.
You can trust the order of the rows inserted
into the DataTable if you iterate
through the DataRowCollection of the
DataTable when you go to read the table.

No matter if I use "for" or "foreach"?

There is no need to use a View unless you want to perform sorting,
filtering, or querying on the DataTable.

I think I might need filtering, but I would like the insertion order to be
preserved all the same.

Of course I might add an additional field keeping the insertion order and
use it for sorting, but anyway, it is more work and more usage of memory.

DW.
 
Back
Top