以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 导入excel怎么实现先判断sql数据库里面所在单位、姓名、电话号码三个字段是否有值,若无就新增,若有就不改变,直接跳过。 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=149092) |
-- 作者:李孝春 -- 发布时间:2020/4/23 10:30:00 -- 导入excel怎么实现先判断sql数据库里面所在单位、姓名、电话号码三个字段是否有值,若无就新增,若有就不改变,直接跳过。 导入excel怎么实现先判断sql数据库里面所在单位、姓名、电话号码三个字段是否有值,若无就新增,若有就不改变,直接跳过。 当前代码如下:(当前代码实现的是删除所在单位等于_UserGroup 的所有数据,想实现在删除前,先判断sql数据库里面所在单位、姓名、电话号码三个字段是否有值,若无就新增,若有就不改变,直接跳过。) Dim dlg As New OpenFileDialog dlg.Filter = "Excel文件|*.xls;*.xlsx" If dlg.ShowDialog =DialogResult.OK Then DataTables("干警信息").sqlDeleteFor("所在单位=\'"& _UserGroup & "\'") Dim t As Table = Tables("干警信息") t.StopRedraw() Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) For n As Integer = 1 To Sheet.Rows.Count -1 Dim r As DataRow = t.DataTable.Find("姓名 = \'" & sheet(n,0).text & "\'") If r Is Nothing Then r = t.DataTable.AddNew() For i As Integer = 0 To sheet.Cols.Count -1 Dim cname As String = sheet(0, i).text If t.Cols.Contains(cname) Then r(cname) = sheet(n, i).Text End If Next Next t.ResumeRedraw() End If DataTables("干警信息").LoadFilter="所在单位=\'"& _UserGroup & "\'" DataTables("干警信息").Load
|
-- 作者:有点蓝 -- 发布时间:2020/4/23 10:38:00 -- Dim dlg As New OpenFileDialog dlg.Filter = "Excel文件|*.xls;*.xlsx" If dlg.ShowDialog =DialogResult.OK Then \'DataTables("干警信息").sqlDeleteFor("所在单位=\'"& _UserGroup & "\'") Dim t As Table = Tables("干警信息") t.StopRedraw() Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) For n As Integer = 1 To Sheet.Rows.Count -1 Dim r As DataRow = t.DataTable.Find("姓名 = \'" & sheet(n,0).text & "\' and 单位=\'" & sheet(n,xxx).text & "\' and 电话号码=\'" & sheet(n,xxx2).text & "\'") If r Is Nothing Then r = t.DataTable.AddNew() For i As Integer = 0 To sheet.Cols.Count -1 Dim cname As String = sheet(0, i).text If t.Cols.Contains(cname) Then r(cname) = sheet(n, i).Text End If Next END IF Next t.ResumeRedraw() End If DataTables("干警信息").LoadFilter="所在单位=\'"& _UserGroup & "\'" DataTables("干警信息").Load
|
-- 作者:李孝春 -- 发布时间:2020/4/23 10:56:00 -- 回复:(有点蓝)Dim dlg As New OpenFileDialogdlg.F... 谢谢有点蓝老师 备注:sheet(n,0) 某字段在excel中的实际排序列 默认从0开始 Dim r As DataRow = t.DataTable.Find("姓名 = \'" & sheet(n,2).text & "\'and 所在单位=\'" & sheet(n,0).text & "\' and 电话=\'" & sheet(n,3).text & "\'") |