以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  请教:合并数据的问题.  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=24242)

--  作者:kevin
--  发布时间:2012/10/9 3:08:00
--  请教:合并数据的问题.

Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.C
cmd.CommandText = "SELECT * From {员工}"
dt = cmd.ExecuteReader()
For Each dr As DataRow In dt.DataRows
    If DataTables("员工").Find("sfzhm = \'" & dr("身份证号") & "\'") Is Nothing Then
        Dim nr As DataRow = DataTables("员工").AddNew()
        For Each dc As DataCol In dt.DataCols
            nr(dc.name) = dr(dc.name)
        Next
    End If
Next

 

以上代码是:合并数据源名称为"text" 中的 "员工"表到本项目中的:"员工" 表
且条件是"身份证号码"相同时,则跳过....

 

而以下这个代码:

Dim Book As New XLS.Book("c:\\test\\订单.xls")
Dim
Sheet As XLS.Sheet = Book.Sheets(0)
Tables("订单").StopRedraw()
\'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
Dim
nms() As String = {"产品","客户","雇员","单价","折扣","数量","日期"}
\'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
For n As Integer = 1 To Sheet.Rows.Count -1
    Dim
r As Row = Tables("订单").AddNew()
    For
m As Integer = 0 To nms.Length - 1
        
r(nms(m)) = Sheet(n,m).Value
    Next
Next
Tables(
"订单").ResumeRedraw()

能否给它增加一个条件,当订单编号相同时,则跳过.

 

由于太多

 


--  作者:狐狸爸爸
--  发布时间:2012/10/9 8:59:00
--  
Dim Book As New XLS.Book("c:\\test\\订单.xls")
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("订单").StopRedraw()
Dim nms() As String = {"订单编号","产品","客户","雇员","单价","折扣","数量","日期"}
\'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
For n As Integer = 1 To Sheet.Rows.Count -1
    If DataTables("订单").Find("sfzhm = \'" & sheet(n,0).Text & "\'") Is Nothing Then
        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()

--  作者:lin_hailun
--  发布时间:2012/10/9 9:02:00
--  
 首先要确定你Excel的订单编号的列在第几列,才能写代码。

Dim Book As New XLS.Book("c:\\test\\订单.xls")
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Tables("订单").StopRedraw()
\'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致
Dim nms() As String = {"订单编号", "产品","客户","雇员","单价","折扣","数量","日期"}
\'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题
For n As Integer = 1 To Sheet.Rows.Count -1
    If DataTables("订单").Find("订单编号 = \'" & sheet(n, 0).Value & "\'") Is Nothing Then
        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()
[此贴子已经被作者于2012-10-9 9:02:57编辑过]

--  作者:kevin
--  发布时间:2012/10/9 12:00:00
--  

狐爸,如果需要合并DBF文件的话,同时也是根据身份证号码如果相同,则跳过行.应该怎么写呢

Dim mg As New Merger
mg.SourcePath = "D:\\SJY\\" \'指定数据文件所在目录
mg.Format = "dbase" \'指定格式
mg.SourceTableName = "123" \'指定要合并的dbase文件,无需扩展名
mg.DataTableName = "xsxxb" \'指定接收数据的表
mg.Merge()


--  作者:lin_hailun
--  发布时间:2012/10/9 15:49:00
--  

 单一条件合并,需要自己编写代码完成。参考

 http://www.foxtable.com/help/topics/2137.htm