Hello,
I would like to create a reusable function (workflow) to filter a DataTable. This function will have a few variable inputs and one output.
Inputs :
A source DataTable [dtSource] containing all the data
A destination DataTable [dtDestination] that will store the filtered data
An array of type string [arrFilterValues] containing the filter values (ex : {“26”, “29”, “01”})
Output :
The destination DataTable [dtDestination] containing the filtered data
Task :
For each value inside the [arrFilterValues] the function needs to loop on the [dtSource] in order to verify if row.Item(0).ToString.StartsWith(arrFilterValue)
Could you please suggest a LINQ expression to execute this filter?
(From d in in_dtData.AsEnumerable()
Let val = d(in_intColIndex).toString.Trim
Let chk = in_arrFilterSet.Any(Function (x) val.StartsWith(x))
Where chk
Select r = d).CopyToDataTable
Both solutions work as expected.
The solution of @ppr is mandatory in case we get the chance to have an empty data table.
As for my case, I already have the resultDataTable in input argument so I need to enrich.
Thank you very much @Praveen_Mudhiraj and @ppr .