DataTable.Select 方法 (String, String)
DataTable.Select 方法 (String, String)
获取按照指定的排序顺序且与筛选条件相匹配的所有 DataRow 对象的数组。
命名空间: System.Data
程序集: System.Data(在 System.Data.dll 中)
下面的示例使用筛选表达式来返回 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]); } }