Dim dt As DataTable = DataTables("成绩")
If dt.Type = 1 OrElse dt.Type = 3 Then
If dt.HasChanges Then
Dim Arys As List(Of String()) = DataTables("成绩").GetValues("学校代码|年级代码")
For Each Ary As String() In Arys
Dim filter As String = CExp("学校代码='{0}' and 年级代码='{1}'",Ary(0),Ary(1))
Dim bhstr As String = Ary(0) & Ary(1)
Dim bj As List(Of String) = DataTables("成绩").GetValues("班级",filter,"班级")
Dim bjlist As new List(Of List(of DataRow))(bj.Count)
Dim max As Integer = 0
For Each s As String In bj
Dim lst As List(of DataRow) = DataTables("成绩").Select(filter & " and 班级 ='" & s & "'","姓名")
If max < lst.Count Then max = lst.Count
bjlist.add(lst)
Next
Dim idx As Integer = 1
Dim dr As DataRow
For i As Integer = 0 To max - 1
For j As Integer = 0 To bjlist.Count - 1
Dim lst As List(of DataRow) = bjlist(j)
If i < lst.Count Then
dr = lst(i)
dr("考号") = bhstr & Format(idx,"0000")
idx += 1
End If
Next
Next
Next
Tables("成绩").Sort = "考号"
End If
End If
经学习请教,以上代码实现了同校,同年级隔班排考号,但发现有个问题:因为一个学校一个年级一学期可能存在多次考试,如半期,月考,期末,因此另加了字段"考试名称"来区分每次考试,如何能实现每次不一样的考试的考号编排.(一个两次考号可以一样,比一学期同年级如人没变化),请老师明示,谢谢!!!