以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  excel文件导入 如何实现导入前进行判断 如果表中已经有相同姓名且所在单位相同的数据 就不新增 直接覆盖数据 如果没有就新增数据  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=135678)

--  作者:李孝春
--  发布时间:2019/5/31 19:13:00
--  excel文件导入 如何实现导入前进行判断 如果表中已经有相同姓名且所在单位相同的数据 就不新增 直接覆盖数据 如果没有就新增数据
excel文件导入  如何实现导入前进行判断  如果表中已经有相同姓名且所在单位相同的数据  就不新增  直接覆盖数据  如果没有就新增数据

代码如下:(如何增加判断呢?请各位老师指导下!谢谢!)
Dim dlg As New OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx"
If dlg.ShowDialog =DialogResult.OK Then
    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

--  作者:有点蓝
--  发布时间:2019/5/31 20:17:00
--  
代码不是已经有判断了吗?不过查询只查询姓名,是不是应该加上单位条件?

Dim r As DataRow = t.DataTable.Find("姓名 = \'" & sheet(n,0).text & "\' and 单位=‘xxxx’")

--  作者:李孝春
--  发布时间:2019/5/31 20:54:00
--  回复:(有点蓝)代码不是已经有判断了吗?不过查询只...
还是会形成重复记录  麻烦老师指导一下  谢谢
--  作者:有点蓝
--  发布时间:2019/5/31 21:05:00
--  
可能数据有空格
Dim r As DataRow = t.DataTable.Find("姓名 = \'" & sheet(n,0).text.trim() & "\' and 单位=‘xxxx’")

还不行就上传实例说明