Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a sql datbase with the following:

Product: Amount:
PCB1 2
PCB1 6
PCB2 54
PCB2 23

im interested in counting the amount of the same product and displaying it in a datagrid view.

just after the sql command and following code to populate the datagridview.

If anyone could help, that would be great.

Many Thanks,
Pete :)
Posted
Comments
PIEBALDconsult 3-Dec-14 10:29am    
Do you mean you want to add a total line to the same grid as the detail data?
If so, you can use a UNION ALL with something like the statement in Solution 1.
peterjames09 3-Dec-14 10:52am    
just read directly from sql table and show on different rows on the datagridview, PCB1 8 and on another row PCB2 77?

1 solution

try this

SQL
select Product,Sum(Amount) as [Amount] from tbl
group by product 
 
Share this answer
 
Comments
Maciej Los 3-Dec-14 10:22am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900