我想在导入数据前,判断”身份证号码”和”在保月份”是否同时一致,如果存在该记录就不导入,不知下面的代码问题出在哪里?请指教,谢谢!
Dim dlg As New OpenFileDialog
dlg.Filter= "Excel文件|*.xls"
If dlg.ShowDialog = DialogResult.Ok Then
Dim c As Integer = 0
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("参加企业保险明细表").StopRedraw()
MessageBox.Show("请确保Excel中的字段顺序为:姓名,身份证号码,在保月份,是否结清,备注,结清类型")
Dim nms() As String = {"姓名","身份证号码","在保月份","是否结清","备注","结清类型"}
For n As Integer = 1 To Sheet.Rows.Count -1
Dim dr As DataRow = e.DataTable.find("身份证号码='" & e.DataRow("身份证号码") & "' and 在保月份 = #" & e.DataRow("在保月份")& "#")
If dr Is Nothing Then
c = c + 1
Dim r As Row = Tables("参加企业保险明细表").AddNew()
For m As Integer = 0 To nms.Length - 1
r(nms(m)) = Sheet(n,m).Value
Next
End If
Next
Tables("参加企业保险明细表").ResumeRedraw()
DataTables("参加企业保险明细表").Save
MessageBox.Show("导入完成,共导入" & c & "条记录")
End If