DataTable Filter with multiple values


I’m trying to filter the DataTable by taking parameters.
Assume that there are values ​​1,2,3,4,5 in the column called Number in the datatable named BerforeDT. Then, when I want to leave only 1, 3, and 5, I try to use this as a parameter.
But when I put {1,3,5} in the DataTable filter, it doesn’t work…
How can I filter multiple values?


If your condition is static, try to use “OR” in filter datatable wizard.


If your condition is dynamic, can you try as the following?
(This assume Number column type is object or string)

arrInt = {1,3,5}
dt = dt.AsEnumerable.Where(Function(r) arrInt.Contains(Int32.Parse(r("Number").ToString))).CopyToDataTable


check if the values are with space or not. Make sure to use trim to compare with a “=” sign. Often blank spaces results in wrong results

Thank you! I’m doing what you said and it’s going well!
Can you explain to me ‘dt.AsEnumerable.Where(Function(r) arrInt.Contains(Int32.Parse(r(“Number”).ToString))).CopyToDataTable’?
How was it filtered?
Thanks again!


dt.AsEnumerable returns IEnumerable<DataRow> and Where method is for filtering IEnumerable<DataRow> by condition described in it.
Function(r) means iterate each datarow as variable r.
The condition is arrInt.Contains(Int32.Parse(r(“Number”).ToString))
This checks whether arrInt : in this case {1,3,5} contains item of Number Column in the datarow. If contains, the datarow will be kept and if not, will be filtered out.


I just confirmed Thanks for explaining!
Is there any way I can use this method to use the activity?
If the value in { } is not fixed, is the only way to use Assign?

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.