以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  请问,自动编号事件出错提示,是什么原因?如何解决?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=143505)

--  作者:leyevee
--  发布时间:2019/11/27 10:53:00
--  请问,自动编号事件出错提示,是什么原因?如何解决?
表中录入了字段更改事件,后出现如下提示:
Exception has been thrown by the target of  an  invocation
是什么原因,如何解决?

--  作者:有点蓝
--  发布时间:2019/11/27 10:57:00
--  
贴出相关代码看看
--  作者:leyevee
--  发布时间:2019/11/27 11:22:00
--  
If e.DataCol.Name = "送达日期" Then
    If e.DataRow.Isnull("送达日期") Then
        e.DataRow("送达编号") = Nothing
    Else
        Dim d As Date = e.DataRow("送达日期")
        Dim y As Integer = d.Year
        Dim fd As Date = New Date(y,1,1)
        Dim ld As Date = fd.addyears(1)
        Dim bh As String = Format(d,"yyyy")
        If e.DataRow("送达编号").StartWith(bh) = False
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(送达编号)","送达日期 >= #" & fd & "# And 送达日期 < #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify"))
            If max > "" Then
                idx = CInt(max.Substring(4,4)) + 1
            Else
                idx = 1
            End If
            e.DataRow("送达编号") = bh & Format(idx,"0000")
        End If
    End If
End If

--  作者:有点蓝
--  发布时间:2019/11/27 11:32:00
--  
这个代码没有问题,也看不出和1楼的错误有什么关系,可能是其他代码的问题。

或者是数据有问题,比如旧数据的编号不符合规范,可以把不符合规范的编号先清空

--  作者:leyevee
--  发布时间:2019/11/27 14:16:00
--  
对不起,占用老师的时间了。是我代码没敲对,StartsWith 敲成了StartWith。
以下代码,运行无误:
If e.DataCol.Name = "送达日期" Then
    If e.DataRow.Isnull("送达日期") Then
        e.DataRow("送达编号") = Nothing
    Else
        Dim d As Date = e.DataRow("送达日期")
        Dim y As Integer = d.Year
        Dim fd As Date = New Date(y,1,1)
        Dim ld As Date = fd.addyears(1)
        Dim bh As String = Format(d,"yyyy")
        If e.DataRow("送达编号").StartsWith(bh) = False
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(送达编号)","送达日期 >= #" & fd & "# And 送达日期 < #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify"))
            If max > "" Then
                idx = CInt(max.Substring(4,4)) + 1
            Else
                idx = 1
            End If
            e.DataRow("送达编号") = bh & Format(idx,"0000")
        End If
    End If
End If