以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  在 datarowadded 事件下的问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=86514)

--  作者:jhd0118
--  发布时间:2016/6/19 12:50:00
--  在 datarowadded 事件下的问题
在子表的 datarowadded 事件内添加代码
希望判断子表第一列“编号”新增行内是否自动给出了新值,如果给出了就执行“物品品名”列赋名的指令。
因为针对“编号”列建立了关联表,所以在关联表下新添加一行的时候,第一列“编号”在新增行内是自动匹配更新父表“编号”列的编号值的,
所以,在父表下操作关联表,代码运行顺利
但是,在子表下,添加空行,总是提示出错:

不懂怎么处理,求指正

...................出错提示.................................
.NET Framework 版本:2.0.50727.8689
Foxtable 版本:2014.11.11.1
错误所在事件:表,使用情况,DataRowAdded
详细错误信息:
调用的目标发生了异常。
未将对象引用设置到对象的实例。
...............................................................

............................代码.............................
If e.DataRow("编号") Is Nothing Then
    
Else
    Dim ar As DataRow = e.DataRow \'新增行的行号
    Dim fr As Integer = ar("编号") \'新增行的编号
    Dim dr As DataRow
    
    With DataTables("使用情况")
        dr= .find("编号=" & fr ) \'新增物品编号的行
        ar("物品品名") =dr("物品品名")
    End With
    e.DataTable.Save()
    
End If

--  作者:jhd0118
--  发布时间:2016/6/19 14:21:00
--  
好吧,我自己找到了,判断列内容为空,在我这个情况下应该是

If e.DataRow.Isnull("物品编号") Then

--  作者:大红袍
--  发布时间:2016/6/20 0:46:00
--  

代码这样写

 

If e.DataRow.IsNull("编号") Then
   
Else
    Dim ar As DataRow = e.DataRow \'新增行的行号
    Dim fr As Integer = ar("编号") \'新增行的编号
    Dim dr As DataRow
       
    dr= DataTables("使用情况").find("编号=\'" & fr & "\'") \'新增物品编号的行
    If dr IsNot Nothing Then
        ar("物品品名") =dr("物品品名")
        e.DataTable.Save()
    End If   
End If


--  作者:大红袍
--  发布时间:2016/6/20 0:47:00
--  

你应该写到DataColChanged事件才对的

 

If e.DataCol.name = "编号" Then
    If e.DataRow.IsNull("编号") Then
       
    Else
        Dim ar As DataRow = e.DataRow \'新增行的行号
        Dim fr As Integer = ar("编号") \'新增行的编号
        Dim dr As DataRow
       
        dr= DataTables("使用情况").find("编号=\'" & fr & "\'") \'新增物品编号的行
        If dr IsNot Nothing Then
            ar("物品品名") =dr("物品品名")
            e.DataTable.Save()
        End If
    End If
End If