• 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.
0
countrymeister
Asked:
countrymeister
  • 2
1 Solution
 
CutSackCommented:
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.
0
 
CutSackCommented:
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).
0
 
pbellovoxCommented:
If your query is dynamic it will also return -1 as the dynamic transaction exists in a different context.
0
 
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.
0

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