It gives error "Specified cast is not valid."
So you're getting an InvalidCastException
in the Field
extension method.
You have to check which column's type does not match to the one you've specified, for example:
totLen = r.Field<int>("Quantity") * r.Field<decimal>("Breath") * r.Field<decimal>("Length")
Above will fail if any of the three columns has a different type than the one you've provided. Maybe Breath
is not a decimal
but a double
.
Edit your question and provide the types in database and we could help to identify the correct types.