Sum of DataTable columns total using Lambda Expression in Entity FrameWork in ASP.Net

Last Reply 9 months ago By dharmendr

Posted 9 months ago
 decimal total = dt.AsEnumerable().Sum(row => row.Field<decimal>("TotalAmount"));



when i try to add the total amount from grid view row then i'm faicing above error sir
Posted 9 months ago
fareed.fd7 says:
decimal total = dt.AsEnumerable().Sum(row => row.Field<decimal>("TotalAmount"));

 First make sure that TotalAmount field should be decimal in the datatable. If this is string then change with the below code.

decimal d = 0;
decimal total = dt.AsEnumerable().Where(row => decimal.TryParse(row["TotalAmount"].ToString(), out d)).Sum(row => d > 0 ? d : 0);

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html