DataTable - 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.
 
Hi Dobieslaw,

I think that Add will always append the row at the end and using a DataView
without sorting will reflect this.
However, to be on the safe side, you might consider using an AutoIncrement
field which will always be corrrectly incremented.
 
Endorsing Miha's comment - as a general rule, if you want to be sure
that a dataset will be displayed in a specific order, it is best to
ensure that there is a field (preferably indexed) which, when you sort
on it, will order the dataset the way you want and to sort it on that
field for display. Although there is a tendency, in practice, for
unsorted datasets to maintain the order in which items were added to
them, this is almost never guaranteed, and Tables retrieved from
relational databases, in particular, cannot be assumed to be sorted,
even on their Primary Key, unless a sort order has been specified.

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.


Please respond to the Newsgroup, so that others may benefit from the exchange.
Peter R. Fletcher
 
Back
Top