还是到黄色部分报错,但是数据是正确传递的
调用的目标发生了异常。
未将对象引用设置到对象的实例。
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