将前面两段代码改成:
dim f As New Filler
f.SourceTable = DataTables("成绩库1")
f.DataTable = DataTables("班单科1")
f.ExcludeExistValue = True
f.Fill()
For Each dr As DataRow In DataTables("班单科1").DataRows
Dim str As String = "[学校] = '" & dr("学校") & "' And [班别] = '" & dr("班别") & "'"
Dim dt As DataTable =DataTables("成绩库1")
Dim fin As DataRow = DataTables("任课信息1").Find(str)
Dim Int As Integer = dt.Compute("Count(学校)", "[语文排名] > 0 ")
dr("参考人数") = dt.Compute("Count(学校)", "[片代码] = '" & dr("片代码") & "'" & "And" & str )
dr("最高分") = Math.Round(dt.Compute("max(语文)","[片代码] = '" & dr("片代码") & "'" & "And" & str ),1)
dr("语文A") = dt.Compute("Count(学校)", "[语文] >= 130 And [语文] < 150" & "And" & str )
dr("语文B") = dt.Compute("Count(学校)", "[语文] >= 110 And [语文] < 130 " & "And" & str )
dr("语文C") = dt.Compute("Count(学校)", "[语文] >= 90 And [语文] < 109 " & "And" & str )
dr("语文D") = dt.Compute("Count(学校)", "[语文] < 90 " & "And" & str )
dr("语文前30人数") = Math.Round(dt.Compute("Count(学校)", str & "And [语文排名] <= " & Int * 0.3),0)
dr("语文优生率") = dr("语文前30人数") / dr("参考人数")*100
dr("语文前60人数") = Math.Round(dt.Compute("Count(学校)", str & "And [语文排名] <= " & Int * 0.6),0)
dr("语文合格率") = dr("语文前60人数") / dr("参考人数")*100
dr("语文平均成绩") = Math.Round(dt.Compute("Avg(语文)",str),1)
If fin IsNot Nothing Then
dr("语文任课教师") = fin("语文")
end if
Next