0

So, I'm attempting to create search exclude functionality on a data table.

I've tried a few things, both the Select() method and I also tried LINQ.

I tried to build a CHARINDEX Select() method function that looked something like:

dt.Select("CHARINDEX (" + searchString + ")");

But it kept throwing formatting errors.

And I tried LINQ with something like:

var filtered = dt.AsEnumerable()
                    .Where(r => !r.Field<String>(col).Contains(searchString));

But in the end I'm getting the entire table returned to me and for the life of me I can't figure out why.

I'd prefer to get the LINQ version of the solution working because I've been told that searching Data Tables with LINQ is more efficient than the Select() method.

Thank you for all of your help.

Prog
  • 33
  • 1
  • 5
  • Both solutions will work if you assign the filtered result to the `DataSource` of `DataGridView`. As a better option, rely on `dr.RowFilter` to filter data table. – Reza Aghaei Nov 05 '17 at 00:52
  • You can use a `DataView` as explained [here](https://stackoverflow.com/a/13012669/331281). – Dejan Nov 05 '17 at 00:52

0 Answers0