user1570048
user1570048

Reputation: 880

VB.NET increase sql value by an integer variable

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

Answers (2)

slugster
slugster

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

andy
andy

Reputation: 6079

By using queries

SELECT ISNULL(Suppbackorder,0)+1 FROM products WHERE catalogid=@catalogid

Upvotes: 1

Related Questions