vb.net mysql update_VB.NET和MySql UPDATE查询

bd96500e110b49cbb3cd949968f18be7.png

I have my codes here without errors (at least not when I Debug it, I use VS 2010), but what I wish to happen is when I click on the add button, the number/s in the textbox(txtQty) would add to the numbers currently saved in the column "Quantity". (ex: txtQty "100" and current on the column is "200", I want to add "100" from the textbox to the column which has "200" and save it as a new number "300". Simple math I know, but the problem is I have yet to know how to use math equations on VB.NET Datagridview or MySql Database This Code executes but when I click Add the numbers in the column return to 0. Any Hint or Tips would be much appreciated, thanks.

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!")

解决方案

your command text must be parameterized also

cmd.CommandText = " UPDATE incomingdeliveries SET Quantity = @iQuantity + Quantity"

cmd.Parameters.Add(New MySqlParameter("@iQuantity", txtQty.Text))

UPDATE 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值