以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助] 值不能为null,参数: key  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=194950)

--  作者:洮沙
--  发布时间:2025/2/9 11:12:00
--  [求助] 值不能为null,参数: key
DataColChanged事件如下代码,开发环境不报错,发布后偶发报如题错误,麻烦老师帮忙看一下,哪里错了,谢谢!
Select e.DataCol.Name
        Case "签订日期","合同种类"
            If e.DataRow.IsNull("签订日期") Or e.DataRow.IsNull("合同种类") Then
                e.DataRow("合同编号") = Nothing
            Else
                Dim d As Date = e.DataRow("签订日期")
                Dim y As Integer = d.Year
                Dim Days As Integer = Date.DaysInMonth(y,12)
                Dim fd As Date = New Date(y,1,1) \'获得该年的第一天
                Dim ld As Date = New Date(y,12,Days) \'获得该年的最后一天
                Dim bh As String = e.DataRow("合同种类") & "-" & Format(d,"yyyy") & "-" \'生成合同编号的前缀
                If e.DataRow("合同编号").StartsWith(bh) = False \'如果单据合同编号前缀不符
                    Dim flt As String
                    flt = "合同种类 = \'" & e.DataRow("合同种类") & "\' And 签订日期 >= \'" & fd & "\' And 签订日期 <= \'" & ld & "\' And [_Identify] <> " & e.DataRow("_Identify") 
                    Dim max1 As String
                    Dim max2 As String
                    max1 = e.DataTable.Compute("Max(合同编号)", flt) \'取得该类别的最大编号
                    max2 = e.DataTable.SQLCompute("Max(合同编号)", flt) \'取得该类别的最大编号
                    Dim idx1 As Integer 
                    Dim idx2 As Integer 
                    If max1 > "" Then \'如果存在最大编号
                        idx1 = CInt(max1.Substring(bh.length, 4))
                    End If
                    If max2 > "" Then \'如果存在最大编号
                        idx2 = CInt(max2.Substring(bh.length, 3))
                    End If
                    Dim idx As Integer = Math.Max(idx1, idx2)
                    idx = idx + 1 \'获得最大编号加1
                    e.DataRow("合同编号") = bh & Format(idx, "0000")
                End If
            End If
    End Select

--  作者:有点蓝
--  发布时间:2025/2/9 20:12:00
--  
看不出什么问题。确定是这个事件报错?截图看看错误详细信息
--  作者:洮沙
--  发布时间:2025/2/10 18:11:00
--  
谢谢蓝老师!我把相关联代码全部检查并重写一遍,目前没有报错。
估计是窗口文本框(绑定到表“合同编号”)代码,
其中有一句代码:e.Sender.Value > ""
修改为:e.Sender.Text > ""
[此贴子已经被作者于2025/2/10 18:18:31编辑过]

--  作者:有点蓝
--  发布时间:2025/2/10 19:48:00
--  
【值不能为null,参数: key】这个错误应该是字典添加的键为空值导致。检查用到字典的地方