Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Sort Dataset?

Tags:

c#

I have Dataset that include table Items, How can I sort this table by Code field ?

thank's in advance

like image 681
Gold Avatar asked Mar 22 '09 08:03

Gold


2 Answers

With DataTable, you usually sort a DataView - for example:

        DataTable table = dataSet.Tables["foo"];
        DataView view = table.DefaultView;
        view.Sort = "Code";

then work with view.

like image 128
Marc Gravell Avatar answered Oct 10 '22 07:10

Marc Gravell


DataSet fileTransferDetail = null; //Data to be sorted.
DataSet result = null; //Declare a dataSet to be filled.

// Sort data
fileTransferDetail.Tables[0].DefaultView.Sort = "ID DESC";
// Store in new Dataset
result.Tables.Add(fileTransferDetail.Tables[0].DefaultView.ToTable());
like image 44
Taran Avatar answered Oct 10 '22 08:10

Taran