-- 请教老师们,下面这段码是想排除当导入的姓名及打卡时间在数据库里有的情况下不导入。如果排除姓名就可以,加上打卡时间就不行,并报错 Conversion from string "姓名= '石飞燕'" to type 'Long' is not valid.
Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog dlg.Filter= "Excel2007文件|*.xlsx|Excel97文件|*.xls" '设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮 Dim ip As New Importer ip.SourcePath = dlg.FileName '指定数据文件\ Dim Str1 As String = FileSys.GetName(dlg.FileName) '从文件路劲中获取文件名称 Dim book As new XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) Tables("hx").StopRedraw() '注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致 Dim nms() As String = {"姓名","出生日期","年龄","电话号码","打卡时间"} '注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题 For n As Integer = 1 To Sheet.Rows.Count -1 Dim dg As String = sheet(n,0).Text Dim dx As String = sheet(n,4).Text If DataTables("hx").Find("姓名= '" & dg & "'" And "打卡时间= '" & dx & "'") Is Nothing Then '如果不存在同编号的订单 Dim r As Row = Tables("hx").AddNew() For m As Integer = 0 To nms.Length - 1 r(nms(m)) = Sheet(n,m).Value Next End If Next Tables("hx").ResumeRedraw() End If Tables("hx").ResumeRedraw() DataTables("hx").Save MessageBox.Show("导入完成")
|