- public DataRow[] Select (
- string filterExpression,
- string sort
- )
参数
- filterExpression
-
要用来筛选行的条件。
- sort
-
一个字符串,它指定列和排序方向。
返回值
与筛选表达式相匹配的 DataRow 对象的数组。
若要形成 filterExpression 参数,请使用与创建 DataColumn 类的 Expression 属性值相同的规则。Sort 参数也使用与创建类的 Expression 字符串相同的规则。
示例
下面的示例使用筛选表达式来返回 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]);
- }
- }
注:select中允许出现的为字符串,切忌!!!
