How to access filtered records after using RowFilter on DataSet?

1.2k views Asked by At

I have a dataset on which I have set a rowfilter:

DateTime minDateVal = (DateTime)ds.Tables[0].Compute("Min(DateTimeField)", "anotherField = 12");

ds.Tables[0].DefaultView.RowFilter = "anotherField=12 and DateTimeField='" + minDateVal + "'";

So after applying this filter, I get rows that satisfy the condition but how can I access to the filtered rows (those which satisfy rowfilter condition)?

Some doubts:

  • To obtain the number of rows that satisfy the rowfilter is it correct to do below?

    ds.DefaultView.Count

    ds.DefaultView.recordCount

  • To access to the rows filtered after applying rowfilter is it correct to do below?

for row 0:

ds.DefaultView.RowViewCache[0]["MyColumn1"].ToString()

for row 1:

ds.DefaultView.RowViewCache[1]["MyColumn1"].ToString()

and so on.

1

There are 1 answers

1
Azar Shaikh On

You Can use ToTable() of Dataview to get Filtered Dataview back to Datatable

DataView dv = ds.Tables[0].DefaultView;

dv.RowFilter = "anotherField=12 and DateTimeField='" + minDateVal + "'";

Datatable result  = dv.ToTable();