Sum DataTable columns of type string
问题 how do i calculate Sum of two rows in datatable which is of type string ? in my case i cannot change column type. i tried these : 1) object objSum; objSum = dt.Compute("Sum(WeightRate)", ""); 2) decimal total = (decimal)dt.Compute("SUM( [WeightRate] )", ""); but no luck... My table : Weightrate No.Ofvehicles 350.50 50 205.00 40 I need result as Weightrate No.Ofvehicle 555.50 90 回答1: The Compute method allows for some rudimentary type conversion: var sum = dt.Compute("Sum(Convert(WeightRate,