Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi there,

i am working on vb.net (access) . data in my table is like.....

CODE         NAME     QTY
 
1           Mango      10
2           Banana     20
3           APPle      05
1           Mango      30
2           Banana     30
1           Mango      12

i want to display above data in gridview like....(total of quantity)

code     Name        Qty
1          Mango        52
2          Banana       50
3          Apple        05

i tried this code, it's only display total data.

Dim t As Integer
 t = 0
   DataGridView1.Rows.Clear()
   ss = "select * from StockIn"
   com = New OleDbCommand(ss, con)
   con.Open()
   dr = com.ExecuteReader()
   While dr.Read
       x = DataGridView1.Rows.Add(+1)
       DataGridView1.Rows(x).Cells(0).Value = dr(0)
       DataGridView1.Rows(x).Cells(1).Value = dr(1)
       t = t + dr(2)
       DataGridView1.Rows(x).Cells(2).Value = t
       End While
   con.Close()
Posted

1 solution

try this
VB
Dim t As Integer
   t = 0
     DataGridView1.Rows.Clear()
     ss = "select code,name,sum(qty) as qty from StockIn group by code,name"
     com = New OleDbCommand(ss, con)
     con.Open()
     dr = com.ExecuteReader()
     if dr.Hasrows() then
       While dr.Read
          DataGridView1.rows.insert(t,dr(0),dr(1),dr(2))
       End While
     end if
     con.Close()
 
Share this answer
 
Comments
[no name] 6-Feb-14 5:34am    
it's work
Thanks
Basmeh Awad 6-Feb-14 6:48am    
you are welcome :-)

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