以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]重复导入问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=185732)

--  作者:myzy
--  发布时间:2023/3/13 16:10:00
--  [求助]重复导入问题
Dim cmd As New SQLCommand
Dim dt As DataTable
Dim sCols() As String = {"订单号","联系人电话","上门日期","时间"}
Dim dCols() As String = {"订单号","电话号码","截止日期","时间"}
cmd.C
cmd.CommandText = "SELEC  T * From {shdd}"
dt = c
For Each dr As DataRow In dt.DataRows
    Dim nr As DataRow = DataTables("派工_Table1").AddNew()
    For i As Integer =0 To sCols.Length -1
        nr(dCols(i)) = dr(sCols(i))
    Next
Next
msgbox("新增" & newcount & "    " & "更新旧数据" & oldcount)
    t.ResumeRedraw()


请教老师:如何通过 ”订单号” 来实现已有相同订单号的行更新,没有的新增呢?更新完,再提示。谢谢
[此贴子已经被作者于2023/3/13 16:13:52编辑过]

--  作者:有点蓝
--  发布时间:2023/3/13 16:20:00
--  
dt = c
For Each dr As DataRow In dt.DataRows
    Dim nr As DataRow = DataTables("派工_Table1").find("订单号=\'" & dr("订单号") & "\'")
if dr is nothing then
dr = DataTables("派工_Table1").addnew
end if
    For i As Integer =0 To sCols.Length -1
        nr(dCols(i)) = dr(sCols(i))
    Next
Next

--  作者:myzy
--  发布时间:2023/3/13 16:41:00
--  
Dim cmd As New SQLCommand
Dim dt As DataTable
Dim sCols() As String = {"订单号","联系人电话","上门日期","时间"}
Dim dCols() As String = {"订单号","电话号码","截止日期","时间"}
cmd.C
cmd.CommandText = "SELEC   T * From {shdd}"
dt = cmd.ExecuteReader()
\'For Each dr As DataRow In dt.DataRows
    \'Dim nr As DataRow = DataTables("派工_Table1").AddNew()
    \'For i As Integer =0 To sCols.Length -1
        \'nr(dCols(i)) = dr(sCols(i))
    \'Next
\'Next
\'
\'
\'dt = c
For Each dr As DataRow In dt.DataRows
    Dim nr As DataRow = DataTables("派工_Table1").find("订单号=\'" & dr("订单号") & "\'")
If dr Is Nothing Then
dr = DataTables("派工_Table1").addnew
End If
    For i As Integer =0 To sCols.Length -1
        nr(dCols(i)) = dr(sCols(i))
    Next
Next

 
    msgbox("新增" & newcount & "    " & "更新旧数据" & oldcount)
    t.ResumeRedraw()
End If
\'



.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2020.5.29.8
错误所在事件:窗口,派工,Button12,Click
详细错误信息:
未将对象引用设置到对象的实例。
谢谢,才开始学。
[此贴子已经被作者于2023/3/13 16:46:57编辑过]

--  作者:有点蓝
--  发布时间:2023/3/13 16:51:00
--  
For Each dr As DataRow In dt.DataRows
    Dim nr As DataRow = DataTables("派工_Table1").find("订单号=\'" & dr("订单号") & "\'")
If nr Is Nothing Then
nr = DataTables("派工_Table1").addnew
End If
    For i As Integer =0 To sCols.Length -1
        nr(dCols(i)) = dr(sCols(i))
    Next
Next

--  作者:myzy
--  发布时间:2023/3/13 16:56:00
--  

此主题相关图片如下:5.png
按此在新窗口浏览图片

  msgbox("新增" & newcount & "    " & "更新旧数据" & oldcount)
    t.ResumeRedraw()
End If
这个没有提示?
[此贴子已经被作者于2023/3/13 16:56:54编辑过]

--  作者:有点蓝
--  发布时间:2023/3/13 17:15:00
--  
变量都没有定义,怎么用咯

dim newcount as integer

For Each dr As DataRow In dt.DataRows
    Dim nr As DataRow = DataTables("派工_Table1").find("订单号=\'" & dr("订单号") & "\'")
If nr Is Nothing Then
nr = DataTables("派工_Table1").addnew
newcount += 1
End If
    For i As Integer =0 To sCols.Length -1
        nr(dCols(i)) = dr(sCols(i))
    Next
Next
msgbox("新增" & newcount & "    " & "更新旧数据" & (dt.DataRows.count - newcount) )