共享网

DataTable.Select 方法 (String, String)
2010-6-2 15:37:42 文章来源: http://www.chr114.com 文章作者: chr114 点击率:
核心提示: DataTable.Select 方法 (String, String) 获取按照指定的排序顺序且与筛选条件相匹配的所有 DataRow 对象的数组。 命名空间:System.Data 程序集:System.Data(在 system.data.dll 中)
C#代码
  1. public DataRow[] Select (   
  2.     string filterExpression,   
  3.     string sort   
  4. )   

参数

filterExpression

要用来筛选行的条件。

sort

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

 

 

返回值

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

备注

若要形成 filterExpression 参数,请使用与创建 DataColumn 类的 Expression 属性值相同的规则。Sort 参数也使用与创建类的 Expression 字符串相同的规则。

示例


下面的示例使用筛选表达式来返回 DataRow 对象的数组。

C#代码
  1. private void GetRowsByFilter()   
  2. {   
  3.     DataTable table = DataSet1.Tables["Orders"];   
  4.   
  5.     // Presuming the DataTable has a column named Date.   
  6.     string expression = "Date > '1/1/00'";   
  7.   
  8.     // Sort descending by column named CompanyName.   
  9.     string sortOrder = "CompanyName DESC";   
  10.     DataRow[] foundRows;   
  11.   
  12.     // Use the Select method to find all rows matching the filter.   
  13.     foundRows = table.Select(expression, sortOrder);   
  14.   
  15.     // Print column 0 of each returned row.   
  16.     for(int i = 0; i < foundRows.Length; i ++)   
  17.     {   
  18.         Console.WriteLine(foundRows[i][0]);   
  19.     }   
  20. }   

 

注:select中允许出现的为字符串,切忌!!!
 

欢迎访问编程之路,请在评论时遵守国家相关法律法规。评论不代表本站观点

  • 访客名称:

2010 编程之路 www.chr114.com All Rights Reserved