2

我的代码在这里没有错误(至少在我调试它时没有,我使用VS 2010),但我希望发生的是当我单击添加按钮时,文本框(txtQty)中的数字/秒会添加到数字中当前保存在“数量”列中。(例如:txtQty“100”,当前列是“200”,我想将“100”从文本框中添加到“200”列并将其保存为新数字“300”。我知道的简单数学,但问题是我还不知道如何使用数学方程式VB.NET DatagridviewMySql Database执行此代码,但是当我单击添加列中的数字时返回 0。任何提示或提示将不胜感激,谢谢。

        cmd.Connection = conn

        Dim Result = "Quantity" + txtQty.Text

        cmd.CommandText = " UPDATE incomingdeliveries SET Quantity ='" & Result & "';"
        cmd.Parameters.Add(New MySqlParameter("@Quantity", txtQty.Text))

        cmd.ExecuteNonQuery()

        MsgBox("Data Added to the Database")

            Me.IncomingdeliveriesTableAdapter.Dispose()
        Me.IncomingdeliveriesTableAdapter.Fill(Me.IncomingDeliveriesDataSet.incomingdeliveries)

            lblCode.Text = ("Tables Refreshed!")
4

1 回答 1

3

您的命令文本也必须参数化

cmd.CommandText = " UPDATE incomingdeliveries SET Quantity = @iQuantity + Quantity"
cmd.Parameters.Add(New MySqlParameter("@iQuantity", txtQty.Text))

更新 1

Using _conn As New MySqlConnection("connectionStr here")
    Using _comm As New MySqlCommand()
        With _comm
            .Connection = _conn
            .CommandText = "UPDATE incomingdeliveries SET Quantity = @iQuantity + Quantity"
            .CommandType = CommandType.Text
            .Parameters.AddWithValue("@iQuantity", txtQty.Text)
        End With
        Try
            _conn.Open()
            _comm.ExecuteNonQuery()
        Catch ex As MySqlException
            Msgbox(ex.Message.ToString())
        End Try
    End Using
End Using
于 2012-10-30T05:21:09.433 回答