I am pretty new to LINQ and ran into a bit of a roadblock that I hope someone can help with. My goal is to filter out of my DT any values that are not integers in the column “Account”. This column has integers, strings and empty strings.
Here are my two attempts so far, that I can’t get to work properly:
- This gets me the error of “cannot infer a common type because more than one type is possible” After researching this here, I tried using the cint function for the return, but still getting an issue.
dt.AsEnumerable.Where(Function(r) If(IsNumeric(r("Account").ToString), r("Account").ToString), False).CopyToDataTable
- This earlier attempt obviously crashes, as there are other datatypes in the column. Unsure if there is a way to skip rows that error. (In my dataset, it is safe to assume integers are larger than 1)
dt.AsEnumerable.Where(Function(r) CInt(r("Account").ToString) > 1).CopyToDataTable
Hoping someone can point me in the right direction. Thank you