DataTable.Select 方法 (String, String)的学习

获取按照指定的排序顺序且与筛选条件相匹配的所有 DataRow 对象的数组。

命名空间:System.Data
程序集:System.Data(在 system.data.dll 中)

语法:

public DataRow[] Select (
string filterExpression,
string sort
)

参数

filterExpression

要用来筛选行的条件。

sort

一个字符串,它指定列和排序方向。

返回值

与筛选表达式相匹配的 DataRow 对象的数组。

示例

private void GetRowsByFilter()
{
    DataTable table = DataSet1.Tables["Orders"];

    // Presuming the DataTable has a column named Date.
    string expression = "Date > '1/1/00'";

    // Sort descending by column named CompanyName.
    string sortOrder = "CompanyName DESC";
    DataRow[] foundRows;

    // Use the Select method to find all rows matching the filter.
    foundRows = table.Select(expression, sortOrder);

    // Print column 0 of each returned row.
    for(int i = 0; i < foundRows.Length; i ++)
    {
        Console.WriteLine(foundRows[i][0]);
    }
}
 

原文地址:https://www.cnblogs.com/fanxiaojun/p/2094250.html