我想从未绑定的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
没有错误,但结果不正确。循环更新失败,我不知道如何。 请有人给我参考解决它。谢谢。