vb.net从数据值分组数据和名称列

时间:2017-02-23 00:55:23

标签: datagridview grouping

当前数据库:

NAME          WEEK         COLOR

AAA            1           Green

AAA            2           Blue

AAA            3           Blue

BBB            1           Red

BBB            3           Green

输出:

NAME     WEEK1      WEEK2       WEEK3

AAA      Green      Blue        Blue

BBB      Red                    Green

Dim weekOfyear = calendar.GetWeekOfYear( dateNow, _ dfi.CalendarWeekRule, _ DayOfWeek.Sunday) 
w1 = weekOfyear - 2 
w2 = weekOfyear - 1 
w3 = weekOfyear 
w4 = weekOfyear + 1 
w5 = weekOfyear + 2 
Dim c As New OleDb.OleDbCommand With c .CommandText = "select [Engineer],[Week],[Status] from [Approved Jobs] where [Week] = '" & w1 & "' and '" & w2 &     "' group by [Engineer]" .Connection = con 
End With
Dim ad As New OleDb.OleDbDataAdapter(c)
    Dim dt As New DataTable
    ad.Fill(dt)
    DataGridView1.DataSource = dt
End Sub

大家好。我真的需要你的帮助。我在学校的这个项目,如上所示,我当前的数据库和我对datagridview的预期输出。我想问一下这可以实现的方法。我一直试图在sql中按名称分组,但我无法获得预期的输出。真的很想听听你的想法。

TIA

0 个答案:

没有答案