本文介绍了添加datagridview列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在使用vb.net(访问)。我桌上的数据就像.....



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想显示以上网格视图中的数据....(总数量)




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尝试此代码,它只显示总数据。




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()

推荐答案

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()


这篇关于添加datagridview列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 09:45