Home All Groups Group Topic Archive Search About

Sorting a DataTable in a DataSet

Author
18 Sep 2006 6:44 PM
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

Author
18 Sep 2006 7:18 PM
Claes Bergefall
Get the DefaultView for the table and then set the Sort property. Something
like:

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


    /claes

Show quoteHide quote
"Brad" <brad.markis***@roche.com> wrote in message
news:%23CL7$J12GHA.5108@TK2MSFTNGP02.phx.gbl...
> 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
>
Author
18 Sep 2006 7:46 PM
Kerry Moorman
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


Show quoteHide quote
"Brad" wrote:

> 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
>
>
>
Author
20 Sep 2006 12:12 PM
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


Show quoteHide quote
"Kerry Moorman" wrote:

> 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" wrote:
>
> > 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
> >
> >
> >