Dim cmd As new SQLCommand
'如果是外部数据源,就加上外部数据源的名字
cmd.CommandText = "select * from {报销名单}"
Dim dt1 As DataTable = cmd.ExecuteReader
cmd.CommandText = "select * from {基本资料}"
Dim dt2 As DataTable = cmd.ExecuteReader
For Each dr As DataRow In dt1.DataRows
If DataTables("病案首页").Find("身份证号 = '" & dr("身份证号") & "' and 入院时间 = #") Is Nothing Then
Dim ndr As DataRow = DataTables("病案首页").AddNew
ndr("身份证号") = dr("身份证号")
ndr("入院时间") = dr("入院时间")
End If
Next
For Each dr As DataRow In DataTables("病案首页").DataRows
Dim fdr1 As DataRow = dt1.Find("身份证号 = '" & dr("身份证号") & "' and 入院时间 = #" & dr("入院时间") & "# and 入院时间 Is not null")
Dim fdr2 = dt2.Find("身份证号 = '" & dr("身份证号") & "'")
If fdr1 IsNot Nothing Then
dr("姓名") = fdr1("姓名")
End If
If fdr2 IsNot Nothing Then
dr("性别") = fdr2("性别")
End If
Next