判断一下,有符合条件的行才执行:
Dim dt As DataTable = DataTables("异动总表")
Dim nums As List(Of String) = dt.GetUniqueValues("学号 is not null", "学号")
Dim idxs As String = ""
For Each num As String In nums
Dim drs As List(Of DataRow) = dt.Select("学号 = '" & num & "'", "异动日期")
For i As Integer = drs.Count - 2 To 0 Step -1
Dim bf As DataTable = DataTables("异动备份")
Dim ndr As DataRow = bf.AddNew()
For Each c As DataCol In bf.DataCols
ndr(c.Name) = drs(i)(c.Name)
Next
idxs = idxs & drs(i)("_Identify") & ","
Next
Next
If idxs > "" Then
dt.DeleteFor("[_Identify] in (" & idxs.Trim(",") & ")")
End If