I am working on a scenario, where I want to filter the Values of a specific column in a data table. I have used datatable.select(“[Column Name]”=condition but the regex expression in giving errors. The columns contains the Zip values of different regions. In that Zip column some times this type of zip value occurs “MS23SX-7” so I want to remove the entire row in which this type of values occur in Zip column.
Any help in this regard will be highly appreciated!
give a try on LINQ or let us know more details on value, pattern and we will help you on the LINQ
In general it would look like this
(From d in YourDataTable.AsEnumerable
Where Not System.Text.RegularExpressions.Regex.IsMatch(d(ColNameOrIndex).toString, YourRegexPattern)
Select r = d).CopyToDataTable
I have modified the LINQ query you provided according to my conditions the query is like that: (From d In dt.AsEnumerable Where Not System.Text.RegularExpressions.Regex.IsMatch(d(Zip).toString, “[a-zA-Z]”) Select r = d).CopyToDataTable
error is this: ZipColumn_test: ‘name’ argument cannot be null. Parameter name: name
I have rephrased your expression like below:
FilterDatatable =
(From d In FilterDatatable.AsEnumerable
Where Not System.Text.RegularExpressions.Regex.IsMatch(d("Zip").toString, "[a-zA-Z]")
Select r = d).CopyToDataTable
And was able to see the resultant in the excel without the values which you have mentioned in the query like “ MS23SX-7 ”
Is your issue is solved or do I miss anything
Also, it would be helpful if you provide us with a screenshot of the error which you’re facing.