Hi I have a linq query as below
var perChange = (from data in globalDS.Tables[0].AsEnumerable().AsParallel()
select data.Field<double>("PercentChange")).ToList();
Now the dataset globalDS contains null as well as varchar values in them. So there is an obvious type cast error that is generated. Is there a way to try.Parse the value in “Percentage Change” column and select only the valid fields.
DataRow.Fieldsupports nullable types:Edit: Since you have mentioned that the field contains strings instead of doubles:
I’ve used this extension to try-parse a string to
double?which is safer than parsing “on the fly” into the local variable, especially withAsParallel: