var GrandTotal = dt.AsEnumerable().Sum(cols => Convert.ToDecimal(cols.Field<string>("TotalPrice")));
is Giving Error:
Unable to cast object of type 'System.Decimal' to type 'System.String'
How can I Correct it?
var GrandTotal = dt.AsEnumerable().Sum(cols => Convert.ToDecimal(cols.Field<string>("TotalPrice")));
is Giving Error:
Unable to cast object of type 'System.Decimal' to type 'System.String'
How can I Correct it?
Copyright © 2021 Jogjafile Inc.
Your
TotalPrice
column contains decimal values, but you are trying to cast row field value tostring
. Cast todecimal
directly instead: