尝试了我能想到的所有组合:String.Empty、IsDBNull。
selectPONumber 从“selectPONumber: [' + JSON.stringify('') + ']” 传递给“ByVal selectPONumber() As String”
StackTrace 指向这个 VB 的第二行
VB
If Not IsDBNull(selectPONumber) Then
If selectPONumber.Length > 1 Then
qry = qry + "and ("
For u As Integer = 0 To selectPONumber.Length - 1
If u <> selectPONumber.Length Then
qry = qry + "and B.PONumber = '" & selectPONumber(u) & "' or "
Else
qry = qry + "and B.PONumber = '" & selectPONumber(u) & "'"
End If
Next
qry = qry + ") "
Else
qry = qry + "and B.PONumber = '" & selectPONumber(0) & "' "
End If
End If
提前谢谢了!
更新
用计数替换了所有长度,并接受了tranceporter的建议。现在,它在“for”行上给出了相同的错误。它是如何通过 If selectPONumber.Length > 1 的?
更新代码
If selectPONumber IsNot Nothing AndAlso selectPONumber.Count > 1 Then
qry = qry + "and ("
For u As Integer = 0 To (selectPONumber.Count - 1)
If u <> selectPONumber.Count Then
qry = qry + "B.PONumber = '" & selectPONumber(u) & "' or "
Else
qry = qry + "B.PONumber = '" & selectPONumber(u) & "'"
End If
Next
qry = qry + ") "
ElseIf selectPONumber(0) <> "" Then
qry = qry + "and B.PONumber = '" & selectPONumber(0) & "' "
End If
解决方案
tranceporter 的解决方案是正确的。我愚蠢地将常规字符串视为代码中其他地方的数组。它开始将整个函数的其余部分都指向 indexoutofbounds。