Dim lst1 As New List(of DataRow)
Dim lst2 As New List(of DataRow)
For Each dr As DataRow In DataTables("学生名单1").DataRows
If DataTables("学生名单2").Find("姓名 = '" & dr("姓名") & "'") Is Nothing Then
lst1.Add(dr)
Else
lst2.Add(dr)
End If
Next
For Each dr As DataRow In lst1
dr("对比结果") = "无此人"
Next
For Each dr As DataRow In lst2
dr("对比结果") = ""
Next
For Each dr As DataRow In DataTables("学生名单2").DataRows
If DataTables("学生名单1").Find("姓名 = '" & dr("姓名") & "'") Is Nothing Then
lst1.Add(dr)
Else
lst2.Add(dr)
End If
Next
For Each dr As DataRow In lst1
dr("对比结果") = "无此人"
Next
For Each dr As DataRow In lst2
dr("对比结果") = ""
Next
或者
For Each dr As DataRow In DataTables("学生名单1").DataRows
If DataTables("学生名单2").Find("姓名 = '" & dr("姓名") & "'") Is Nothing Then
dr("对比结果") = "无此人"
Else
dr("对比结果") = ""
End If
Next
For Each dr As DataRow In DataTables("学生名单2").DataRows
If DataTables("学生名单1").Find("姓名 = '" & dr("姓名") & "'") Is Nothing Then
dr("对比结果") = "无此人"
Else
dr("对比结果") = ""
End If
Next
两者效率不同
另外还要表draw事件中设一下“红色显示”