更新未绑定的datagridview没有错误但是结果失败

时间:2013-04-23 09:11:33

标签: mysql .net vb.net datagridview

我想从未绑定的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

没有错误,但结果不正确。循环更新失败,我不知道如何。 请有人给我参考解决它。谢谢。

0 个答案:

没有答案