I have the following query that takes a DataTable
and counts the number of times a value appears in the countField
column.
var countField = "class"
var query = from row in myDataTable.AsEnumerable()
group row by row.Field<string>(countField)
into sumry
orderby sumry.Count() descending
select new
{
Text = sumry.Key,
CountofRows = sumry.Count()
};
This works as expected, unless the column contains decimal values. I am not familiar enough with linq
to know what to change to allow it to count the instances of a decimal value.
How can I make this statement more robust so it will work for any data type contained in the indicated column?