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?
 
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
 
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
 
plusone3055Author Commented:
MlandaT
your code added them together  IE 10 + 10 = 1010
I need 10 + 10 = 20

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.