Solved

getting the sum of a field within my dataset

Posted on 2010-09-23
6
1,748 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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