我想从未绑定的 datagridview 行更新 mysql 表,我使用的是未绑定的 datagridview,因为当我想用 odbc 驱动程序添加绑定的 datagridview 时,我的 VS2005 没有响应。
Using connection As New MySqlConnection(connectionString) Dim cmdText As String = "UPDATE titem set no = '" & TextBoxX1.Text & "', kdbarang = @column1 " Dim command As New MySqlCommand(cmdText, connection) connection.Open() Dim transaction As MySqlTransaction = connection.BeginTransaction() command.Transaction = transaction Try For i As Integer = 0 To dgvitem.Rows.Count - 2 command.Parameters.Clear() command.CommandText = cmdText command.Parameters.Add("@Column1", MySqlDbType.VarChar).Value = dgvitem.Rows(i).Cells(1).Value command.ExecuteNonQuery() Next MessageBox.Show("Data Berhasil Disimpan") Catch ex As Exception MessageBox.Show(ex.Message) Finally connection.Close() End Try End Using End Sub
没有错误,但结果不正确。循环更新失败,我不知道如何。请有人给我参考来解决它。谢谢你。