日期:2014-05-20 浏览次数:20978 次
Dim da1 As DataTable = New DataTable
da1.Columns.Add("id")
da1.Columns.Add("name")
da1.Columns.Add("su", Type.GetType("System.Decimal"))
Dim dr As DataRow = da1.NewRow()
dr("id") = 1
dr("name") = "张三"
dr("su") = 10.0
da1.Rows.Add(dr)
dr = da1.NewRow()
dr("id") = 1
dr("name") = "张三"
dr("su") = 20.0
da1.Rows.Add(dr)
dr = da1.NewRow()
dr("id") = 2
dr("name") = "张三"
dr("su") = 30.0
da1.Rows.Add(dr)
dr = da1.NewRow()
dr("id") = 1
dr("name") = "李四"
dr("su") = 30.0
da1.Rows.Add(dr)
dr = da1.NewRow()
dr("id") = 1
dr("name") = "李四"
dr("su") = 40.0
da1.Rows.Add(dr)
Dim tem1 = From k In da1.Rows.Cast(Of DataRow)()
Group k By id = k.Field(Of String)("id"), name = k.Field(Of String)("name") Into g = Group, su = Sum(k.Field(Of Decimal)("su"))
Select id, name, su
For Each c In tem1
Console.WriteLine("{0},{1},{2}", c.id, c.name, c.su)