Solved

getting the sum of a field within my dataset

Posted on 2010-09-23
6
1,718 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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