Hi,
I want to sum all values in a column in a data table.
I tried to assign
MyDT.Compute(“SUM(ColumnName)”, “”).ToString and
MyDT.AsEnumerable.Sum(Function(a)Convert.ToDouble(a(“ColumnName”).ToString))
But I get System.InvalidOperationException error in both cases.
How can I solve this?
(From d in dtData.AsEnumerable Where Not (isNothing(d("ColumnName")) OrElse String.IsNullorEmpty(d("ColumnName").toString.Trim)) Select v = CDbl(d("ColumnName").toString.Trim)).Sum(Function (x) x)
This expression is to sum the value in the Amount column
(From d in DtRemove.AsEnumerable Where Not (isNothing(d(0)) OrElse String.IsNullorEmpty(d(0).toString.Trim)) Select v = Double.Parse(d(0).toString.Trim,System.Globalization.CultureInfo.CreateSpecificCulture("Es-es"))).Sum(Function (x) x)