阅读背景:

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

来源:互联网 
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 Sub

End Module
Module Module1

    Sub Main()

        Dim tab



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: