Specified cast is not valid error while using linq on Datatable

Hi All,

I’m trying to execute below linq query on a datatable.
(from row in InwardDT.AsEnumerable() where row.Field(of Integer)(“Income”) > 4000 select row).CopyToDataTable. It throws me the below error
“Assign: Specified cast is not valid.” . However, the same query works when I make use of string field
(from row in InwardDT.AsEnumerable() where row.Field(of String)(“City”) = “Mumbai” select row).CopyToDataTable. -> Works as expected.

Have attached the xaml file for reference.
InwardData.xlsx (8.1 KB)
ExcelScrubbing.xaml (8.5 KB)

Any kind of assistance would be of great help…

Thank you in advance.

Hi llangos

Use this code (from a in InwardDT.AsEnumerable() where(convert.ToInt32(a(“Income”))>4000) select a).CopyToDataTable

Regards
Amaresan.P

2 Likes

Thanks a lot @amaresan. It worked :slight_smile:

1 Like

Welcome…Happy automation

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