Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 11-Mar-18 0:52am
v2
Comments
Maciej Los 4-Mar-13 10:21am    
What have you done till now?

1 solution

Try:
VB
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
 
Share this answer
 
Comments
rotsen28 4-Mar-13 22:24pm    
Thanks for your solution. But i just want to ask what is @QU?
OriginalGriff 5-Mar-13 3:57am    
@QU is a parameter name - it ties the position you want to use it in the SQL command with the Parameter value you set in the AddWithValue statement.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900