如何使用VB.NET从数据库中扣除数量 [英] how to deduct a quantity from a database using VB.NET
问题描述
你好,我是新来的。
我打算创建一个简单的POS系统,但我不知道如何从数据库中扣除数量。
i有一个名为Database1.mdb的数据库
我有一个名为tblitem的表
i有2个字段名称itemname和quantity
在VB.Net上,我有1个文本框和1个按钮。
每次按下按钮,我想从数据库中扣除一定数量取决于我在extbox上输入的数字
例如我在我的数据库中:
ItemName:apple
数量:100
如果我在文本框中输入1并按下按钮,它将从数据库中扣除1个苹果
< br $>
ItemName:apple
数量:99
请帮帮我。我不知道如何编码。请帮我。抱歉我的英语
hello, i am new here.
I am planning to create a simple POS system but i don't know how to deduct a quantity from the database.
i have a database named "Database1.mdb"
and I have a table named "tblitem"
i have 2 field names "itemname" and "quantity"
On VB.Net, i have 1 textbox and 1 button.
Each time i press the button, i want to deduct a quantity from the database depends on the number i input on the extbox
for example i have in my database:
ItemName:apple
Quantity: 100
and if i input "1" on the textbox and press the button it will deduct 1 apple from the database
ItemName: apple
Quantity: 99
please help me. i don't know how to code it. please help me. sorry for my english
推荐答案
尝试:
Try:
Using con As New SqlConnection(strConnect)
con.Open()
Using com As New SqlCommand("UPDATE tblitem SET [quantity]=[quantity] - @QU WHERE itemname=@IN", con)
com.Parameters.AddWithValue("@QU", myTextBox.Text)
com.Parameters.AddWithValue("@IN", "apple")
com.ExecuteNonQuery()
End Using
End Using
这篇关于如何使用VB.NET从数据库中扣除数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!