Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating an POS screen which uses inventory and I need to reduce the inventory item picked by 1 each time the user clicks the datagridview.
When the user clicks on the datagridview aka dgproducts I want the quantity of dgProducts.SelectedRows(i).Cells(3).Value)which is the quantity field in the access database to be reduced by one. The table is products.


The user should be able to click on the product + of the row, and it should reduce the quantity of that item by one each time it's clicked.

Then when an item is deleted from the list manually by clicking on the item in the list and then delete button... it has to go back into inventory and update the table.***


------------------------------------------------------------------------
So I am at this point, which is not going to work for obvious reasons.
How do I deduct 1 which is in the txtquantity box from the cell 3 and have it update? would it be something like dgProducts.SelectedRows(i).Cells(3).Value= Val(txtquantity.Text)-dgProducts.SelectedRows(i).Cells(3).Value ?
Not sure of the syntax but does this seem logical or is there another way to do this.

myqry = "Update Products Set "
myqry = myqry + " Quantity = '" & dgProducts.SelectedRows(i).Cells(3).Value & "',"
myqry = myqry + " WHERE "
myqry = myqry + " Quantity = " & Val(txtquantity.Text)
mycmd = New OleDbCommand(myqry, conn)
mycmd.ExecuteNonQuery()

I get index is out of range error for the code above anyway ( which is really strange because it ie quantity field is cell 3, not 2 , not 4 ...tested it out on a textbox and it's 3)
Posted

To begin with, you change variable type in your quantity. The first time, you say it's a string (enclosing it with single quotes) but the second time, you treat it as a numeric.

That right there might screw you up.

Secondly, I assume you realize that you need to have the where clause include a unique product id, or any product with that quantity would be changed.
 
Share this answer
 
Comments
mindserve 12-Oct-10 18:40pm    
thx

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