|
-
Dec 4th, 2000, 07:25 AM
#1
Thread Starter
Addicted Member
Hi All,
Can anyone tell me how to calculate the total sum from a column in a datagrid and output the result to a textbox. I have a datagrid which retrieves two columns of data for example:
Type_______Count
RED _________2
BLUE_________4
GREEN________1
WHITE________2
The count is done using a query on a SQL server database to retrieve this information. What i need is for the total of the count to be displayed in a separate text box.
Any Ideas would be appreciated.
Colin
-
Dec 4th, 2000, 09:10 AM
#2
Member
Colin,
presumably you are using a recordset as the data source for the datagrid.
This means you can either
1/ scroll through the recordset, incrementing the value of a variable, with the value from the count field and when you reach the end of the recordset populate the text box with the variable
e.g
dim a as integer
sql for query.......
open recordset rs.......
populate datagrid with recordset....
a = 0
rs.movefirst
do while not rs.eof
a = a + rs.fields(1).value
rs.movenext
loop
textbox.value = a
rs.close
2/ fire another query at the sql database, but just count the affected records, without grouping by type.
Hope that helps
Ian
-
Dec 4th, 2000, 10:13 AM
#3
Thread Starter
Addicted Member
Thats great, thanks for your help
Colin
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|