Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何对数据集进行排序?_C# - Fatal编程技术网

C# 如何对数据集进行排序?

C# 如何对数据集进行排序?,c#,C#,我有包含表项的数据集,如何按代码字段对该表进行排序 thank's prevent使用DataView对象并对其调用排序方法。或者,如果数据集来自SQL,则在将其加载到数据集中之前,使用ORDER BY子句对其进行排序。使用DataTable,通常对DataView进行排序-例如: DataTable table = dataSet.Tables["foo"]; DataView view = table.DefaultView; view.Sor

我有包含表项的数据集,如何按代码字段对该表进行排序


thank's prevent

使用DataView对象并对其调用排序方法。或者,如果数据集来自SQL,则在将其加载到数据集中之前,使用ORDER BY子句对其进行排序。

使用
DataTable
,通常对
DataView
进行排序-例如:

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

然后使用
view

以及如何在此数据集上运行任何查询?
DataView
对象没有
Sort
方法。它确实有一个
Sort
属性;尽管这没有解释如何对
数据视图进行排序。
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());