Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.c
Dim schoolname As String = user.group
cmd.CommandText = "SELE CT 考试名称,学校,年级,学校班级,总分,班序,校序,[_Identify] from {小生表}"
dt = cmd.ExecuteReader(True)
Dim Arys As List(Of String()) = dt.GetValues("考试名称|学校|年级")
For Each Ary As String() In Arys
Dim drs As List(Of DataRow) = dt.Select("[考试名称] = '" & ary(0) & "'And [学校] = '" & ary(1) & "'and [年级] ='" & ary(2) & "'", "总分 DESC")
For n As Integer = 0 To drs.Count - 1 '遍历所有行
If n > 0 AndAlso drs(n)("总分") = drs(n-1)("总分") Then '如果总分和上一行相同
drs(n)("校序") = drs(n-1)("校序") '则排名等于上一行
Else
drs(n)("校序") = n + 1 '设置排名
End If
Next
Next
Dim Arys1 As List(Of String()) = dt.GetValues("考试名称|学校|年级|学校班级")
For Each Ary1 As String() In Arys1
Dim drs As List(Of DataRow) = dt.Select("[考试名称] = '" & ary1(0) & "'And [学校] = '" & ary1(1) & "'and [年级] ='" & ary1(2) & "'And [学校班级] = '" & ary1(3) & "'", "总分 DESC")
For m As Integer = 0 To drs.Count - 1 '遍历所有行
If m > 0 AndAlso drs(m)("总分") = drs(m-1)("总分") Then '如果总分和上一行相同
drs(m)("班序") = drs(m-1)("班序") '则排名等于上一行
Else
drs(m)("班序") = m + 1 '设置排名
End If
Next
Next
Dim Arys2 As List(Of String()) = dt.GetValues("考试名称|年级")
For Each Ary2 As String() In Arys2
Dim drs As List(Of DataRow) = dt.Select("[考试名称] = '" & ary2(0) & "' And [年级] = '" & ary2(1) & "'", "总分 DESC")
For m As Integer = 0 To drs.Count - 1 '遍历所有行
If m > 0 AndAlso drs(m)("总分") = drs(m-1)("总分") Then '如果总分和上一行相同
drs(m)("区序") = drs(m-1)("区序") '则排名等于上一行
Else
drs(m)("区序") = m + 1 '设置排名
End If
Next
Next
dt.save()
DataTables("小生表").load
老师,我想用上面代码对成绩表排班序,校序,区序,效率很低,要等很久,请问如何能快速完成,前提是小生表不能加载,请指教,谢谢