Sorting a DataTable in a DataSet

  • Thread starter Thread starter Brad
  • Start date Start date
B

Brad

Is there an easy way to sort a DataTable in a DataSet? I've tried a variety
of ideas, but none of them seems to work. I'm reading in the data from an
XML file and I want to sort the list of results, one of the "tables", by
date then send the DataSet off for further processing. Any suggestions
would be greatly appreciated.

TIA

Brad
 
Get the DefaultView for the table and then set the Sort property. Something
like:

ds.Tables[0].DefaultView.Sort = "DateColumn ASC"


/claes
 
Brad,

I don't believe the dataset or datatable has a way to physically re-arrange
rows to be in some sorted order, which sounds like what you want.

You can, of course, sort a view of the data, such as the defaultview of the
datatable. But the rows in the datatable will not be re-arranged.

Kerry Moorman
 
Brad,

As Cor pointed out in another newsgroup, the .Net 2.0 version of the
dataview has a ToTable method. You can use a dataview to sort the rows of a
datatable and then use ToTable to create a new data table with rows that will
be in sorted order.

Kerry Moorman
 
Back
Top