linq to DataTable group by用法(VB.Net语法)

来源:互联网 发布:电脑连接网络出现红叉 编辑:程序博客网 时间:2024/05/22 14:46
Module Module1    Sub Main()        Dim table As New DataTable        table.Columns.Add("A", GetType(Integer))        table.Columns.Add("B", GetType(Integer))        table.Columns.Add("C", GetType(Integer))        table.Columns.Add("S", GetType(Integer))        table.Columns.Add("S1", GetType(Integer))        table.Columns.Add("S2", GetType(Integer))        table.Rows.Add(1, 1, 1, 1, 1, 1)        table.Rows.Add(1, 1, 1, 2, 1, 1)        table.Rows.Add(1, 1, 2, 3, 2, DBNull.Value)        table.Rows.Add(1, 1, 2, 4, 2, 1)        table.Rows.Add(1, 1, 3, 5, DBNull.Value, 1)        table.Rows.Add(2, 1, 3, 6, 3, 1)        table.Rows.Add(2, 1, 3, 7, 3, 1)        table.Rows.Add(2, 1, 4, 8, 4, 1)        table.Rows.Add(2, 1, 4, 9, 4, 1)        table.Rows.Add(2, DBNull.Value, 4, DBNull.Value)        table.Rows.Add(2, DBNull.Value, 4, 11)        Dim temp = From p In table.AsEnumerable                                    Group p By Key = New With {Key .A = p("A"), Key .B = p("B"), Key .C = p("C")} Into g = Group                                    Select New With {                                        .key = Key, _                                        .Suryo1 = g.Sum(Function(x) If(IsDBNull(x("S")), 0, x("S")))                                    }        Dim a = temp.ToList()        Dim s = ""    End SubEnd Module


0 0
原创粉丝点击