VB.NET和MySql UPDATE查询 [英] VB.NET and MySql UPDATE query
问题描述
VS 2010
),但我希望发生的是当我点击添加按钮,文本框中的数字(txtQty)将添加到当前保存在数量列中的数字。 (例如:txtQty100,列上的当前值为200,我想从文本框添加100到具有200的列,并将其保存为新的数字300。简单的数学我知道,但问题是我还没有知道如何使用 VB.NET
Datagridview
或 MySql数据库
此代码执行,但当我单击添加列中的数字返回0.任何提示或提示将不胜感激,谢谢。 cmd.Connection = conn
Dim Result =Quantity+ txtQty.Text
cmd.CommandText = UPDATE incomingdeliveries SET Quantity ='&&';
cmd.Parameters.Add(New MySqlParameter(@ Quantity,txtQty.Text))
cmd.ExecuteNonQuery ()
MsgBox(数据添加到数据库)
Me.IncomingdeliveriesTableAdapter.Dispose()
Me.IncomingdeliveriesTableAdapter.Fill(Me.IncomingDeliveriesDataSet.in
lblCode.Text =(Tables Refreshed!)
您的命令文本也必须参数化
cmd.CommandText =UPDATE incomingdeliveries SET数量= @iQuantity + Quantity
cmd.Parameters.Add(New MySqlParameter(@ iQuantity,txtQty.Text))
更新1
使用_conn作为新的MySqlConnection(connectionStr here )
使用_comm作为新的MySqlCommand()
与_comm
.Connection = _conn
.CommandText =UPDATE incomingdeliveries SET Quantity = @iQuantity + Quantity
。 CommandType = CommandType.Text
.Parameters.AddWithValue(@ iQuantity,txtQty.Text)
结束
尝试
_conn.Open()
_comm.ExecuteNonQuery ()
Catch ex As MySqlException
Msgbox(ex.Message.ToString())
结束尝试
结束使用
结束使用
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
这篇关于VB.NET和MySql UPDATE查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!