Dim dtb As New DataTableBuilder("表B")
Dim Names As New List(Of String)
dtb.AddDef("班级",Gettype(String),10)
dtb.AddDef("姓名",Gettype(String),10)
For Each v As String In DataTables("学生成绩").GetValues("科目")
dtb.AddDef(v, Gettype(Double))
Names.Add(v)
Next
dtb.Build()
For Each v As String() In DataTables("学生成绩").GetValues("班级|姓名")
Dim dr1 As DataRow = DataTables("表B").AddNew()
dr1("班级") = v(0)
dr1("姓名") = v(1)
For Each dr2 As DataRow In DataTables ("学生成绩").Select("班级 = '" & v(0) & "' And 姓名 = '" & v(1) & "'")
dr1(dr2("科目")) = dr2("分数")
Next
Next
Dim s As String
For i As Integer = 0 To names.Count - 1
s = s & "+isnull(" & names(i) & ",0)"
Next
DataTables("表B").DataCols.Add("总分",Gettype(Double),s.trim("+")) ',"[语文] + [英语] + [数学] + [物理] + [化学]")
MainTable = Tables("表B")