How to get return value for the number of rows affected by update command
i read from help files that "For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. " Anyone know how to get the return value from the query below?
Below is the normal way i did in vb.net, but how to check for the return value. Please help.
Public Sub CreateMySqlCommand(myExecuteQuery As String, myConnection As SqlConnection)
Dim myCommand As New SqlCommand(myExecuteQuery, myConnection)
End Sub 'CreateMySqlCommand
I'm unsure of how to include the " [BOL} @@rowcount ". Do you mean that i should add a parameter to return @@rowcount or there is other way to do it? I'm new to this, would you please give me an example.
@@Rowcount stored the number of records affected by the immediately prior statement. The value is lost as soon as another statement is executed, so you must either use it immediately or store it in a procedure variable:
declare @RecordsAffected Int
Update/Select/Delete some records from somewhere....
set @RecordsAffected = @@RowCount
Look up @@Rowcount in Books Online for more details.
If it's not practically useful, then it's practically useless.