以文本方式查看主题

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

--  作者:紫色幽魂
--  发布时间:2019/7/11 12:41:00
--  [求助]报错
这两个位置总是报错,是怎么回事儿
调用的目标发生了异常。
未将对象引用设置到对象的实例。


        Dim bh1 As String
        Dim bh2 As String
        If e.DataRow.IsNull("接样日期") Then
            e.DataRow("委托单编号") = Nothing
        Else
            Dim bh As String = Format(e.DataRow("接样日期"),"yyyyMMdd") \'取得编号的8位前缀
            If e.DataRow("委托单编号").StartsWith(bh) = False \'如果编号的前8位不符
                Dim max As String
                Dim idx As Integer
                max = DataTables("理化_统计总表").Compute("Max(委托单编号)","接样日期 = #" & e.DataRow("接样日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大编号
                If max > "" Then \'如果存在最大编号
                    idx = CInt(max.Substring(8,2)) + 1 \'获得最大编号的后2位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                bh1 = bh & Format(idx,"00")
                Dim dr1 As DataRow = DataTables("理化_已有编号").SQLFind("编号 = \'"& bh1 &"\'")
                If dr1 Is Nothing
                    e.DataRow("委托单编号") = bh1
                Else
                        bh2 = bh1
                    For i As Integer = 1 To 100
                        bh1 = val(bh2) + i
                        Dim dr2 As DataRow = DataTables("理化_已有编号").SQLFind("编号 = \'"& bh1 &"\'")
                        If dr2 Is Nothing
                            e.DataRow("委托单编号") = bh1
                            Return
                        End If
                    Next
                End If
            End If
msgbox("1-3")
        End If

--  作者:有点蓝
--  发布时间:2019/7/11 13:49:00
--  
For i As Integer = 1 To 100
                        bh1 = bh & Format(idx + i,"00")
                        Dim dr2 As DataRow = DataTables("理化_已有编号").SQLFind("编号 = \'"& bh1 &"\'")
                        If dr2 Is Nothing
                            e.DataRow("委托单编号") = bh1
                            Return
                        End If
                    Next

--  作者:紫色幽魂
--  发布时间:2019/7/11 15:46:00
--  
还是到黄色部分报错,但是数据是正确传递的
调用的目标发生了异常。
未将对象引用设置到对象的实例。


        Dim bh1 As String
        If e.DataRow.IsNull("接样日期") Then
            e.DataRow("委托单编号") = Nothing
        Else
            Dim bh As String = Format(e.DataRow("接样日期"),"yyyyMMdd") \'取得编号的8位前缀
            If e.DataRow("委托单编号").StartsWith(bh) = False \'如果编号的前8位不符
                Dim max As String
                Dim idx As Integer
                max = DataTables("理化_统计总表").Compute("Max(委托单编号)","接样日期 = #" & e.DataRow("接样日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大编号
                If max > "" Then \'如果存在最大编号
                    idx = CInt(max.SubString(8,2)) + 1 \'获得最大编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                bh1 = bh & Format(idx,"00")
                Dim dr1 As DataRow = DataTables("理化_已有编号").SQLFind("编号 = \'"& bh1 &"\'")
                If dr1 Is Nothing
                    e.DataRow("委托单编号") = bh1
                ElseIf dr1 IsNot Nothing
                    For i As Integer = 1 To 99
                        bh1 = bh & Format(idx + i,"00")
                        Dim dr2 As DataRow = DataTables("理化_已有编号").SQLFind("编号 = \'"& bh1 &"\'")
                        If dr2 Is Nothing
                            e.DataRow("委托单编号") = bh1
                            Return
                        End If
                    Next
                End If
            End If
        End If


--  作者:有点蓝
--  发布时间:2019/7/11 16:00:00
--  
这个赋值代码不可能出错的。出错详细信息发上来,或者截图看看