Dim pr As DataRow For Each dr1 As DataRow In DataTables("表A").DataRows If dr1.IsNull("编号") Then dr1("单位") = Nothing Else Dim drs As List(Of datarow) = DataTables("表B").Select("编号 = '" & dr1("编号") & "' And 年月 <= '" & dr1("年月") & "'", "年月 desc") if drs.Count > 0 Then pr = drs(0) dr1("单位") = pr("单位") Else dr1("单位") = Nothing End If End If Next