Reputation: 337
I have a SqlCommand
UPDATE table SET intColumn = intColumn + 1 WHERE id = @id
Is there a way to get the new value of intColumn
in the same SqlCommand
?
Something like
UPDATE table
SET intColumn = intColumn + 1
WHERE id = @id;
SELECT intColumn
with ExecuteScalar
?
for example:
Dim x as int32 = sqlCommand.ExecuteScalar("sql")
and the x is the new value of the intColumn
?
Upvotes: 1
Views: 410
Reputation: 12271
The SQL query should be framed as below
sqlCommand.ExecuteScalar("UPDATE table SET intColumn=intColumn+1
OUTPUT INSERTED.intColumn
WHERE id=@id")
Upvotes: 1