gpt4 book ai didi

mysql - VB.NET 和 MySql UPDATE 查询

转载 作者:行者123 更新时间:2023-11-29 02:02:03 25 4
gpt4 key购买 nike

我的代码在这里没有错误(至少在调试时没有,我使用 VS 2010),但我希望发生的是当我点击添加按钮时,数字/文本框 (txtQty) 中的 s 将添加到当前保存在“数量”列中的数字。 (例如: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!")

最佳答案

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

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

关于mysql - VB.NET 和 MySql UPDATE 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13133068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com