Solved

getting the sum of a field within my dataset

Posted on 2010-09-23
6
1,724 Views
Last Modified: 2012-05-10
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?
0
Comment
Question by:scm0sml
6 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33741924
Dim sumObject As Object
sumObject = objBatchRecords.tables(0).Compute("local_amount", "")
0
 

Author Comment

by:scm0sml
ID: 33741955
im getting:
Cannot evaluate. Expression 'System.Data.NameNode' is not an aggregate.
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 125 total points
ID: 33741970
My mistake, forget the sum ....

Dim sumObject As Object
sumObject = objBatchRecords.tables(0).Compute("Sum(local_amount)", "")
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Assisted Solution

by:madhav_ghatole
madhav_ghatole earned 125 total points
ID: 33741978
Try this

objBatchRecords.tables(0).Compute("Sum(local_amount)", "")
0
 
LVL 7

Assisted Solution

by:klakkas
klakkas earned 125 total points
ID: 33741985
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
 
LVL 18

Assisted Solution

by:John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou earned 125 total points
ID: 33743071
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question