我的程序有一种奇怪的情况。 虽然它适用于大多数用户,但是一些不同的用户正在收到此错误:
现在请注意错误不是常规"索引超出范围"这是由数组或列表之外的引用引起的 - 但它的特定"插入索引超出范围"。 我试图通过谷歌搜索找到类似的案例而没有太多运气,而且对于我的生活,我不知道为什么这个特定的子因素导致了这个例外。
请记住:
我认为这可能是一个.Net问题,我不知道,也许有些用户没有安装更新的.Net框架。
我很欣赏有关这些主题的任何想法。
导致错误的子例程: (由于显而易见的原因,不得不用X&替换一些信息)
Private Sub SendRequest_Click(sender As Object, e As EventArgs) Handles SendRequest.Click
'Add current data in X to the Request Table sql table.
Dim ReqQuery As String
Dim cnReq As System.Data.OleDb.OleDbConnection
Dim cmdReq As New System.Data.OleDb.OleDbCommand
Dim SKUcounter As Integer
cnReq = New System.Data.OleDb.OleDbConnection("XXX")
cmdReq.Connection = cnReq
'Define SQL Parameters
With cmdReq
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
.Parameters.Add("@X", OleDb.OleDbType.VarChar, 800)
End With
Try
cnReq.Open()
Catch err As OleDb.OleDbException
Dim errorMsg As String
Dim i As Integer
errorMsg = ""
For i = 0 To err.Errors.Count - 1
errorMsg += "Index #" & i.ToString() & ControlChars.Cr _
& "Message: " & err.Errors(i).Message & ControlChars.Cr _
& "NativeError: " & err.Errors(i).NativeError & ControlChars.Cr _
& "Source: " & err.Errors(i).Source & ControlChars.Cr _
& "SQLState: " & err.Errors(i).SQLState & ControlChars.Cr
Next i
End Try
'Loop through each row in X and add to sql table
For SKUcounter = 0 To X.Rows.Count - 2
ReqQuery = "Insert Into Requests (X, X, X, X, X, X, X, X, X, X, X, X, X," _
& "X, X, X, X, X, X, X, X, X, X, X, X, X, X) Values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
cmdReq.CommandText = ReqQuery
Try
With cmdReq
.Parameters("@X").Value = UserPrincipal.Current.DisplayName
.Parameters("@X").Value = String.Format("{0:MM/dd/yyyy HH:mm:ss}", DateTime.Now)
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("SiVersion").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("WiFiIPNCol").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("BTYN").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("VPROYN").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("BTIPTNCol").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("WiGigIPNCol").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("WiGigSSID").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("WiGigDID").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("WiGigNVMTypeCol").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("DueDateCol").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("ProductCode").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("WiGigCode").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("Regulatory").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("HWFF").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("DID").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("WiFiSSID").Value
.Parameters("@X").Value = "New"
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("OPSCommentsCol").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("ProductYear").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("BUS").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("OEM").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("SAR").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("RegulatorySpecialSettings").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("RequestorEmail").Value
.Parameters("@X").Value = DGVrequest.Rows(SKUcounter).Cells("BTproductID").Value
End With
Catch ex1 As Exception
MsgBox("Error sendReq - " + vbCrLf + ex1.ToString)
End Try
cmdReq.ExecuteNonQuery()
Next
'Clear Xfrom data.
If X.Columns.Contains("StatusQ") Then
X.Columns.Remove("StatusQ")
End If
dtReq.Clear()
dsReq.Clear()
X.DataSource = dtReq
X.DataSource = Nothing
'Mark flag so "Changes Not Saved" will not appear.
FirstOpenFlag = True
'Reload data.
GetRequestsTableOpen(X.Text)
MsgBox("Request Sent Successfuly!")
End Sub