anjum
anjum

Reputation: 2541

How to return a dataset from a dataset filtering value

I want to return a dataset filter from a static dataset.

Is it possible.?

Upvotes: 1

Views: 3638

Answers (1)

Arsen Mkrtchyan
Arsen Mkrtchyan

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

Related Questions