getting the sum of a field within my dataset

I have a dataset objBatchRecords.

It has a field in table(0) called local_amount.

I want the sum of this field.....how do I do this?
scm0smlAsked:
Who is Participating?
 
DhaestConnect With a Mentor Commented:
My mistake, forget the sum ....

Dim sumObject As Object
sumObject = objBatchRecords.tables(0).Compute("Sum(local_amount)", "")
0
 
DhaestCommented:
Dim sumObject As Object
sumObject = objBatchRecords.tables(0).Compute("local_amount", "")
0
 
scm0smlAuthor Commented:
im getting:
Cannot evaluate. Expression 'System.Data.NameNode' is not an aggregate.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
madhav_ghatoleConnect With a Mentor Commented:
Try this

objBatchRecords.tables(0).Compute("Sum(local_amount)", "")
0
 
klakkasConnect With a Mentor Commented:
If you want the sum of all fields, you should do this:

Dim sumObject As Object
sumObject = objBatchRecords.tables(0).Compute("Sum(local_amount)", "")

If you want the sum for each Employee, then you should first get the distinct Employees and then call this function for each one, like this:

dim EmployeeSum as new List(of object)
For Each Employee as String in DistinctEmployees
        EmployeeSum.add( objBatchRecords.tables(0).Compute("Sum(local_amount)", "Employee='" + Employee + "'"))
Next
0
 
John (Yiannis) ToutountzoglouConnect With a Mentor Instructor Multiengine PilotCommented:
just something else ...

Check also the Dbnull.Value cause otherwise COMPUTE function returns Nothing
               If sumObject Is DBNull.Value Then
                    Me.SumLabel1.Text = 0
                Else
                    Me.SumLabel1.Text =sumObject
                End If

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.