How to Sort Dataset?

前端 未结 3 1171
时光取名叫无心
时光取名叫无心 2021-01-02 04:10

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

thank\'s in advance

相关标签:
3条回答
  • 2021-01-02 04:48

    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.

    0 讨论(0)
  • 2021-01-02 04:50

    Use a DataView object and call the Sort method on it. Or, if your dataset came from SQL, use the ORDER BY clause to sort it before it gets loaded into the dataset.

    0 讨论(0)
  • 2021-01-02 04:51
    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());
    
    0 讨论(0)
提交回复
热议问题