Reputation: 2541
I want to return a dataset filter from a static dataset.
Is it possible.?
Upvotes: 1
Views: 3638
Reputation: 50712
You can filter Rows, by DataTable.Select function
private void GetRowsByFilter(){
DataTable myTable;
myTable = DataSet1.Tables["Orders"];
// Presuming the DataTable has a column named Date.
string strExpr;
strExpr = "Date > '1/1/00'";
DataRow[] foundRows;
// Use the Select method to find all rows matching the filter.
foundRows = myTable.Select(strExpr);
// Print column 0 of each returned row.
for(int i = 0; i < foundRows.Length; i ++){
Console.WriteLine(foundRows[i][0]);
}
}
Also You can get filtered DataSet by setting RowFilter property like this
ds.Tables[<table name>].DefaultView.RowFilter = "ProductId=5"
Look here for other ways to do filtering
But all of this methods does not create new DataSet with filtered data, if you need it , you should copy filtered rows manually I guess...
Upvotes: 2