• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1258
  • Last Modified:

command.ExecuteNonQuery return value

I just would like to know if I excute a stored procedure which does some updates and then some inserts.

What will be the return value , for example it does 6 updates and 10 inserts.
Will it return 16 or just 10.
  • 2
1 Solution
That's spooky. I was just updating a stored procedure that does something similar.

Mine does 4 updates and 4 inserts and it always returns 8 as the result of ExecuteNonQuery.

Note that if you include SET NOCOUNT ON in your proc, then it won't return anything.
Sorry, should have been more specific, with SET NOCOUNT ON the proc will return -1.

Otherwise, it will return the total number of rows affected by the query (both insert and update).
If your query is dynamic it will also return -1 as the dynamic transaction exists in a different context.
countrymeisterAuthor Commented:
I had the NOCOUNT set to on. I did read that setting it boosts performance., so I left it as is
But i added another OUT parameter to retrun the rows affected.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now