Foxtable(狐表)用户栏目专家坐堂 → 表datacolchanged报错


  共有1843人关注过本帖树形打印复制链接

主题:表datacolchanged报错

帅哥哟,离线,有人找我吗?
deliangzhaoe
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:361 积分:3436 威望:0 精华:0 注册:2012/7/24 7:15:00
表datacolchanged报错  发帖心情 Post By:2019/3/20 19:08:00 [只看该作者]

表中无行时,新增一行报错两次:
.NET Framework 版本:2.0.50727.5420
Foxtable 版本:2018.10.9.1
错误所在事件:表,安全费用使用,DataColChanged
详细错误信息:
调用的目标发生了异常。
未将对象引用设置到对象的实例。

DataColChanged事件:
'修改日期列时,年度月度可根据日期列自动修改
If e.DataCol.name = "日期" Then
    If e.DataRow.IsNull("日期") Then '是否为空
        e.DataRow("月度") = Nothing '如果为空,则月度为空
        e.DataRow("年度") = Nothing
    Else
        e.DataRow("月度") = month(e.DataRow("日期"))
        e.DataRow("年度") = year(e.DataRow("日期"))
    End If
End If

'上月余额
Select Case e.DataCol.name
    Case "企业名称"
        If e.DataRow.IsNull("企业名称") Then
            e.DataRow("上月余额") = Nothing
        Else
            Dim fdr As DataRow = e.DataTable.find("年度 = '" & e.DataRow("年度") - 1 & "' and 月度 = '12' and 企业名称 = '" & e.DataRow("企业名称") & "'","本月余额",0)
            Dim fdr1 As DataRow = e.DataTable.find("月度 = '" & e.DataRow("月度") - 1 & "' And 年度 =  '" & e.DataRow("年度") & "' and 企业名称 = '" & e.DataRow("企业名称") & "'","本月余额",0)
            If e.DataRow("月度") = "1"  Then
                If fdr IsNot Nothing Then
                    e.DataRow("上月余额") =  fdr("本月余额")
                Else
                    e.DataRow("上月余额") = "0"
                End If
            ElseIf e.DataRow("月度") > "1"  Then
                If fdr1 IsNot Nothing Then
                    e.DataRow("上月余额") =fdr1("本月余额")
                Else
                    e.DataRow("上月余额") = "0"
                End If
            End If
        End If
    Case "日期"
        If e.DataRow.IsNull("日期") Then
            e.DataRow("上月余额") = Nothing
        Else
            Dim fdr As DataRow = e.DataTable.find("年度 = '" & e.DataRow("年度") - 1 & "' and 月度 = '12' and 企业名称 = '" & e.DataRow("企业名称") & "'","本月余额",0)
            Dim fdr1 As DataRow = e.DataTable.find("月度 = '" & e.DataRow("月度") - 1 & "' And 年度 =  '" & e.DataRow("年度") & "' and 企业名称 = '" & e.DataRow("企业名称") & "'","本月余额",0)
            If e.DataRow("月度") = "1"  Then
                If fdr IsNot Nothing Then
                    e.DataRow("上月余额") =  fdr("本月余额")
                Else
                    e.DataRow("上月余额") = "0"
                End If
            ElseIf e.DataRow("月度") > "1"  Then
                If fdr1 IsNot Nothing Then
                    e.DataRow("上月余额") =fdr1("本月余额")
                Else
                    e.DataRow("上月余额") = "0"
                End If
            End If
        End If
End Select

'本月应提额
Select Case e.DataCol.name
    Case "企业名称"
        If e.DataRow.IsNull("企业名称") Then
            e.DataRow("本月应提额") = Nothing
        Else
            Dim r1 As DataRow = DataTables("安全费用提取").find("企业名称 = '" & Tables("安全费用使用").current ("企业名称") & "' And 年度 =  '"& Tables("安全费用使用").current ("年度") &"'")
            If r1 IsNot Nothing Then
                e.DataRow("本月应提额") = r1("每月提取额")
            Else
                e.DataRow("本月应提额") = "0"
            End If
        End If
    Case "日期"
        If e.DataRow.IsNull("日期") Then
            e.DataRow("本月应提额") = Nothing
        Else
            Dim r1 As DataRow = DataTables("安全费用提取").find("企业名称 = '" & Tables("安全费用使用").current ("企业名称") & "' And 年度 =  '"& Tables("安全费用使用").current ("年度") &"'")
            If r1 IsNot Nothing Then
                e.DataRow("本月应提额") = r1("每月提取额")
            Else
                e.DataRow("本月应提额") = "0"
            End If
        End If
End Select


'本月支出额
If e.DataCol.name = "数量" Then
    If e.DataRow.IsNull("数量") Then '是否为空
        e.DataRow("本月支出额") = Nothing '如果为空,则为空
    Else
        e.DataRow("本月支出额") = DataTables("安全费用使用").Compute("Sum(金额)","月度 = '" & e.DataRow("月度") & "' And 年度 = '" & e.DataRow("年度") & "' and 企业名称 = '" & e.DataRow("企业名称") & "'")
    End If
End If

'按照企业名称和日期列排序
If e.DataCol.name = "数量" Then
    If e.DataRow IsNot Nothing Then '不为空
        Tables("安全费用使用").Sort = "企业名称,日期"  '按企业名称和日期排序
    Else
    End If
End If

请老师帮忙看一下,代码哪里有问题。谢谢!


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/3/20 21:59:00 [只看该作者]

看看是不是这句代码报错

 

Tables("安全费用使用").Sort = "企业名称,日期"  '按企业名称和日期排序

 

学会调试定位出错位置 http://www.foxtable.com/webhelp/scr/1485.htm

 


 回到顶部
帅哥哟,离线,有人找我吗?
deliangzhaoe
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:361 积分:3436 威望:0 精华:0 注册:2012/7/24 7:15:00
  发帖心情 Post By:2019/3/23 14:23:00 [只看该作者]

datacolchanged事件中这段代码有问题:
'本月应提额
Select Case e.DataCol.name
    Case "企业名称"
        If e.DataRow.IsNull("企业名称") Then
            e.DataRow("本月应提额") = Nothing
        Else
            Dim r1 As DataRow = DataTables("安全费用提取").find("企业名称 = '" & Tables("安全费用使用").current ("企业名称") & "' And 年度 =  '"& Tables("安全费用使用").current ("年度") &"'")
            If r1 IsNot Nothing Then
                e.DataRow("本月应提额") = r1("每月提取额")
            Else
                e.DataRow("本月应提额") = "0"
            End If
        End If

    Case "日期"
        If e.DataRow.IsNull("日期") Then
            e.DataRow("本月应提额") = Nothing
        Else
            Dim r2 As DataRow = DataTables("安全费用提取").find("企业名称 = '" & Tables("安全费用使用").current ("企业名称") & "' And 年度 =  '"& Tables("安全费用使用").current ("年度") &"'")
            If r2 IsNot Nothing Then
                e.DataRow("本月应提额") = r2("每月提取额")
            Else
                e.DataRow("本月应提额") = "0"
            End If
        End If
End Select
请老师帮忙看一下。表中无行时,新增一行报错。表中已有行,新增一行时正常。日期列自动填入今天日期,企业名称自动填入当前登录者的所在分组。

[此贴子已经被作者于2019/3/23 14:25:21编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:106067 积分:539428 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/3/23 14:45:00 [只看该作者]

Dim r1 As DataRow = DataTables("安全费用提取").find("企业名称 = '" & e.DataRow ("企业名称") & "' And 年度 =  '"& e.DataRow("年度") &"'")

或者

if Tables("安全费用使用").current isnot nothing then
    Dim r2 As DataRow = DataTables("安全费用提取").find("企业名称 = '" & Tables("安全费用使用").current ("企业名称") & "' And 年度 =  '"& Tables("安全费用使用").current ("年度") &"'")
            If r2 IsNot Nothing Then
                e.DataRow("本月应提额") = r2("每月提取额")
            Else
                e.DataRow("本月应提额") = "0"
            End If
end if

 回到顶部