• 0

Advanced Sql to Dataset query


Question

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?

Edited by zaidgs
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Just so I'm clear, you want to filter based on the sequence of characters, too? So, "he" won't match anything other than words that have "he" in sequence, like "hello", "the", "helium", etc, but not "echo", "haste", etc...

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.