DataTable.Select(String, String) 方法

  • 943
  • 0

摘要:DataTable.Select(String, String) 方法

利用DataTable.select()多載多一個排序(sort) : asc遞增,desc遞減

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

MSDN範例 : 

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]);
       }
   }