以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  求助  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=85525)

--  作者:674140303
--  发布时间:2016/5/27 11:30:00
--  求助

想从入库表中提取单位与产品字段自动添加到库存表中,麻烦给改一下下面的代码。


If MainTable.Name = "库存" Then
    DataTables("库存").DataRows.clear()
    Dim  Arys As List(Of String())
    Arys = DataTables("入库").GetValues("单位|产品")
    Dim dr As DataRow = DataTables("库存").addnew()
    dr("单位|产品") = Arys
End If



--  作者:大红袍
--  发布时间:2016/5/27 12:09:00
--  
If MainTable.Name = "库存" Then
    DataTables("库存").DataRows.clear()
    Dim  Arys As List(Of String())
    Arys = DataTables("入库").GetValues("单位|产品")
    For Each ary() As String In arys
        Dim dr As DataRow = DataTables("库存").addnew()
        dr("单位") = Ary(0)
        dr("产品") = Ary(1)
    Next
End If

--  作者:674140303
--  发布时间:2016/5/27 12:14:00
--  
谢谢,还有一个问题:
    按这个代码执行,每次切换到库存表,都会重新核算所有的行,能不能加一个判
断,已经存在的行就不用重新增加,只增加新增的行?如何实现?

--  作者:大红袍
--  发布时间:2016/5/27 12:18:00
--  
If MainTable.Name = "库存" Then
    Dim  Arys As List(Of String())
    Arys = DataTables("入库").GetValues("单位|产品")
    For Each ary() As String In arys
        Dim dr As DataRow = DataTables("库存").find("单位 = \'" & ary(0) & "\' and 产品 = \'" & ary(1) & "\'")
        If dr Is Nothing Then DataTables("库存").addnew()
        dr("单位") = Ary(0)
        dr("产品") = Ary(1)
    Next
End If

--  作者:674140303
--  发布时间:2016/5/27 13:40:00
--  
谢谢
--  作者:674140303
--  发布时间:2016/5/27 14:10:00
--  
加了判断条件的代码不能执行。错误显示为:

.NET Framework 版本:2.0.50727.3655
Foxtable 版本:2016.5.13.1
错误所在事件:项目,MainTableChanged
详细错误信息:
Object reference not set to an instance of an object.


--  作者:大红袍
--  发布时间:2016/5/27 14:14:00
--  
4楼代码不可能报错,请认真测试。
--  作者:674140303
--  发布时间:2016/5/28 12:37:00
--  
.NET Framework 版本:2.0.50727.5477
Foxtable 版本:2016.5.13.1
错误所在事件:项目,MainTableChanged
详细错误信息:
未将对象引用设置到对象的实例。


我把2楼的代码复制到库存表的MainTableChanged中,执行正常,我用4楼的代码替换掉2楼的代码,执行显示上面的提示,这是为什么?

--  作者:674140303
--  发布时间:2016/5/28 12:46:00
--  
If MainTable.Name = "库存" Then
    Dim  Arys As List(Of String())
    Arys = DataTables("入库").GetValues("单位|产品")
       MessageBox.show(1)
    For Each ary() As String In arys
       MessageBox.show(2)
        Dim dr As DataRow = DataTables("库存").find("单位 = \'" & ary(0) & "\' and 产品 = \'" & ary(1) & "\'")
        If dr Is Nothing Then DataTables("库存").addnew()
      messagebox.show(3)
        dr("单位") = Ary(0)
        messagebox.show(4)
        dr("产品") = Ary(1)
        messagebox.show(5)
    Next
End If


用这个方法测试,前三步能正常显示,第四步就显示不了了。
       

--  作者:blackzhu
--  发布时间:2016/5/28 12:52:00
--  
If MainTable.Name = "库存" Then
    Dim  Arys As List(Of String())
    Arys = DataTables("入库").GetValues("单位|产品")
       MessageBox.show(1)
    For Each ary() As String In arys
       MessageBox.show(2)
        Dim dr As DataRow = DataTables("库存").find("单位 = \'" & ary(0) & "\' and 产品 = \'" & ary(1) & "\'")
        If dr Is Nothing Then
       dr =  DataTables("库存").addnew()
      messagebox.show(3)
        dr("单位") = Ary(0)
        messagebox.show(4)
        dr("产品") = Ary(1)
        messagebox.show(5)
    Next
End If