add numbers together in query

my query
select record from database where ect ect...

the query returns reocrds  lets say it returned 4 records
recrod 1 = 1
record 2 = 2
record 3 = 3
record 4 = 4

currently my output is

 If myReader.HasRows Then
                        myReader.Read()
                        MessageBox.Show(CStr((myReader.Item("Record "))))


which gives me a popup of 1 ... a popup of 2... a popup of 3.. and a popup of 4  

what i want is just one popup that added those recrods together  
 (1 popup with the value of 10)

   please help


LVL 22
plusone3055Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MlandaTCommented:
While myReader.HasRows

dim total as long = 0
While myReader.Read  
   total += myReader.Item("Record")
End While  

MessageBox.Show(total)

End While
0
MlandaTCommented:
Oops! sorry...outer most should not be a "WHILE" but an "IF"

If myReader.HasRows Then

dim total as long = 0
While myReader.Read  
   total += myReader.Item("Record")
End While  

MessageBox.Show(total)

End If

Open in new window

0
BidonetCommented:
In your loop, simply add the results to a variable.

EX: result=result+myreader.Item("Record")

Then, aftter the loop, show your message box with the result variable.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
plusone3055Author Commented:
MlandaT
your code added them together  IE 10 + 10 = 1010
I need 10 + 10 = 20

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.