i am trying to sum a column of datatable in vb.net but i am getting this error
invalid usage of aggregate function sum and type string.
Sample:
dim sum as integer = dtfilter.Compute("sum(Amount)", "1=1")
Now I am using Custom function, I getting the result...Example:
dim sum as integer = CustomCompute(dtfilter, "Amount")
Private Function CustomCompute(ByVal Datatable As DataTable, ByVal SumColumn As String)
Dim retval As Double = 0
Try
If Datatable IsNot Nothing Then
For Each dr As DataRow In Datatable.Rows
retval = retval + Convert.ToInt32(dr(SumColumn))
Next
Return retval
Else
Return 0
End If
Catch ex As Exception
Return 0
End Try
End Function
Result:
0 Comments