Colby Bradbury
Colby Bradbury

Reputation: 77

SQL, Change the number value of a field. In Visual basic

Im programming a business application as part of an assignment and ran across a problem I have never had to face before.

Im wondering is it possible to update the value of the field QuantityonHand in this statement WITHOUT grabbing it first with another statement and assigning it to a variable.

Google is turning up nothing like what im looking for, thanks!

        cmd = New OleDbCommand("UPDATE Inventory SET QuantityOnHand = ? WHERE ProductID = ?", Con)

        Prm = New OleDbParameter("QuantityOnHand ", )
        cmd.Parameters.Add(Prm)

        Prm = New OleDbParameter("ProductID ", "003")
        cmd.Parameters.Add(Prm)

        cmd.ExecuteNonQuery()

Upvotes: 1

Views: 510

Answers (1)

The other answer is pretty poor. You wisety used Parameters, so just embed an expression in the SQL:

UPDATE Inventory SET QuantityOnHand = (QuantityOnHand  + ?) WHERE ProductID = ? 

pass positives to increase, negative vals to decrease

Upvotes: 3

Related Questions