We help IT Professionals succeed at work.
Get Started

VB.Net - DataTable Looping/Grouping and Getting Sum

Jimbo99999
Jimbo99999 asked
on
2,397 Views
Last Modified: 2016-01-29
Good Day Experts!

I have what seems to be a a straightforward little project, but I would like to check with you to see if there is a better way to do it.  My DataTable looks something like this:

Customer          Invoice          Amount
A                           123               $10
A                           546               $20
A                           111               $15
B                           999               $33
B                           888               $44
C                           765               $66
C                           777               $22

I need to loop through the DataTable and total amount based on Customer A=$45  B=$77 C=$88.
As I loop, I need to stop adding to the total amount when the Customer changes.  But, how do I dynamically create the variables to hold the total amounts? It feels like I need to run a Select Customer, Sum(Amount) on DataTable Group By Customer query on the DataTable.

Can you help me with suggestions on how to get started on achieving my end goal?

Thanks,
jimbo99999
Comment
Watch Question
Developer
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE