Re: Filtering strongly-typed datasets

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Use the DataView:

DataView dv = new DataView(dataSet.Tables["Foo"]);
dv.RowFilter = "age > 18 and name like 'A%'";
foreach (DataRowView row in dv)
{
  //...
}

-Brock
DevelopMentor
http://staff.develop.com/ballen



Is there a way of nicely filtering a strongly typed dataset with a
SQL-esque query or somesuch? A couple of times now, I have wanted
filter a dataset I have obtained from a generic method and pull out
the rows I am actually interested in.

So far I have just relied on using a for-each loop and applying an if
statement to each row in turn to determine whether it should be used.

eg.
foreach (TypedDataSet.testInfoRow row in TestDS.testInfo.Rows)
{
if (row.State == 1)
{
//do something with the row
}
}
This is a bit lame because and you can't seem to manually create a new
filtered DS by adding datarows from the unfiltered original DS either.
You can remove. So any processing you want to do on your filtered data
must be performed in the for-each loop.

I know that in plain-old untyped datasets you can easily create a
dataview using a SQL-esque query, but of course then you lose the
benefits of the strongly typed-ness. There doesn't seem to be
something like a strongly typed dataview.

Any thoughts? In my experience, filtering data client side is quite a
common occurrence and it would be nice to get an efficient way of
doing this. .NET 2.0 perhaps?

Thanks,

Tom




.



Relevant Pages

  • Re: foreach with options?
    ... foreach(object o in myClassIntances) ... public FilterFunction Filter; ... public bool Contains{return Parent.Contains&& ... public IDictionary<TKey, TValue> Parent; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: foreach broken in my script
    ... my @Filter =; ... my @DNS =; ... foreach my $vm { ...
    (perl.beginners)
  • RE: directory operations
    ... If you did want to filter based on a regular expression, you can always do it the long way: ... opendir|| die; ... foreach my $file{ ...
    (perl.beginners)
  • Dataset performance
    ... For example the first thing I do is to filter that table with so many ... foreach(DataRow dr in ds.TableWithManyData.Select(FILTER)){ ... Maxi Menasches ...
    (microsoft.public.dotnet.framework.adonet)