Datatable.Select() method, can you specify "TOP"?

  • Thread starter Thread starter Derrick
  • Start date Start date
D

Derrick

or is there some other MaxRows type of prop so you can limit result set?

Thanks in advance!

Derrick
 
Derrick,

No, you can not limit the result set when you make this call. You will
have to filter or copy the rows you want after the select is performed.

Hope this helps.
 
private void GetRowsByFilter(){
DataTable myTable;
myTable = DataSet1.Tables["Orders"];
// Presuming the DataTable has a column named Date.
string strExpr;
string strSort;
strExpr = "Date > '1/1/00'";
// Sort descending by column named CompanyName.
strSort = "CompanyName DESC";
DataRow[] foundRows;
// Use the Select method to find all rows matching the filter.
foundRows = myTable.Select(strExpr, strSort);
// Print column 0 of each returned row.
for(int i = 0; i < foundRows.Length; i ++){
Console.WriteLine(foundRows[0]);
}
}
 
Back
Top