Solved

getting the sum of a field within my dataset

Posted on 2010-09-23
6
1,710 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now