我正在尝试将数据网格视图中的数据更新回 SQL 服务器,但出现错误
" 索引超出范围。必须为非负数且小于集合的大小。参数名称:索引 "
我的代码如下,任何帮助将不胜感激
Try
SQLConnection = New MySqlConnection()
SQLConnection.ConnectionString = connstr
SQLConnection.Open()
Console.WriteLine("MySQL version : {0}", SQLConnection.ServerVersion)
SQL = ""
For J = 0 To DataGridView1.Rows.Count - 1
SQL = SQL & " UPDATE `ntechtbs`.`a2sbkgsys` SET `NumberOfPax`='" & DataGridView1.Item(J, 1).Value & "', `PAXName`='" & DataGridView1.Item(J, 2).Value & "',`Origin`='" &
DataGridView1.Item(J, 3).Value & "',`Destination`='" & DataGridView1.Item(J, 4).Value & "', `Services`='" & DataGridView1.Item(J, 5).Value & "',`ArrivalDate`='" & DataGridView1.Item(J, 6).Value & "',`DepartureDate`='" & DataGridView1.Item(J, 7).Value & "',`BookingReference`='" & DataGridView1.Item(J, 8).Value & "',`Status`='" & DataGridView1.Item(J, 9).Value & "',`PriceQuote`='" & DataGridView1.Item(J, 10).Value & "',`AgencyPin`='" & DataGridView1.Item(J, 11).Value & "',`AgentPin`='" & DataGridView1.Item(J, 12).Value & "',`SIPCODE`='" & DataGridView1.Item(J, 13).Value & _
"WHERE ID=" & DataGridView1.Item(J, 0).Value & ";"
Next
MsgBox(SQL)
Dim cmd As MySqlCommand = New MySqlCommand(SQL, SQLConnection)
Dim i As Integer = cmd.ExecuteNonQuery()
If (i > 0) Then
MsgBox("Record is Successfully Updated")
Else
MsgBox("Record is not Updated")
End If
SQLConnection.Close()