I have a list box that contains list of people and purchases. One column shows how much each person spent. I would like to add the rows of this column up and get a total. I have seen code like: SELECT SUM (Purchases) FROM Customers; where Purchases is the column and Customers is the table. I don’t seem to be able to get this to work so could anyone offer some help with a short exaple on how to take the total and show in a text box. All assistance is greatly appreciated.
I take it that means that the data in the Listbox is coming from your database, so you are using the database to sum up that column. That’s fine and should work. What part of it is failing?
One issue to be aware of is using a column spec like “sum(purchases)” results in a nonstandard field name in the result set. You might want to specify a field name like
SELECT SUM(Purchases) AS purchase_sum FROM Customers …
You can then use
dim summary as double = rs.Field(“purchase_sum”).DoubleValue
Otherwise, you probably need to use rs.IdxField to get the value.
while not rs.EOF