Reputation: 880
whats the best way to increase the slected sql value by a vb.net integer variable
should i first get the value of the cell i want to increase, or there is a way to do the increment using a single command?
one thing i am not sure of is how can i save the value to a vb.net integer variable
here is what i have so far
sqlcmd.CommandText = "SELECT Suppbackorder FROM products WHERE catalogid=@catalogid"
sqlcmd.Parameters.Add(New SqlParameter("@catalogid", someid))
Upvotes: 0
Views: 925
Reputation: 49984
It's not at all obvious which value you want to increase by a specified amount, here is something that may help guide you (excuse my rusty VB):
Dim myMagicValue as Int = 10
sqlcmd.CommandText = "UPDATE products SET mySpecialColumn = mySpecialColumn + @magicValue WHERE catalogid=@catalogid"
sqlcmd.Parameters.Add(New SqlParameter("@catalogid", someid))
sqlcmd.Parameters.Add(New SqlParameter("@magicValue", myMagicValue))
As you can see your WHERE
clause remains the same, all we do is change the SELECT
to an UPDATE
.
Upvotes: 2
Reputation: 6079
By using queries
SELECT ISNULL(Suppbackorder,0)+1 FROM products WHERE catalogid=@catalogid
Upvotes: 1