Zaid

Zaid

  • NA
  • 1
  • 0

Advanced Sql to Dataset query

Aug 3 2009 2:31 PM
I want to make dynamic Sql to Dataset query, where I filter the dataset consecutively, like this:

Assume we have a dataset called DS that contains a table called Table1 and a string field called Column1, and an array of strings ArStr. I want to do this code in C#:

 var query = from c in DS.Table1 select c;
foreach(string s in ArStr)
{
query = query.Where(c => c.Column1.Contains(s));
}


What I expect is that after the code has run, the "query" results in columns that contains all of the strings in ArStr. However the quey actually only returns the rows based on the last Where condition.

To elaborate, consider that Column1 contains those values:
"hi"
"hello"
"bye"

And that ArStr contains:
"h", "e"

I expect to get "hello" based on the two conditions, but I am getting "hello" and "bye" because it only activates the last filter.

How can I do this advanced filtering procedure?

Answers (1)