Sorting a DataTable in a DataSet

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
 
C

Claes Bergefall

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

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


/claes
 
G

Guest

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
 
G

Guest

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
 

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