2011年7月21日 星期四

DataTable.Select 方法 (String, String)

語法:

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


飯粒:

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

沒有留言:

張貼留言