Click here to Skip to main content
15,883,859 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
In my stored procedure I have used 2 insert statement.When I am executing sp using executenonquery(),it return me number of row affected by 2 statement. Suppose number of row affected by Query 1 is 2 and number of row affected by Query 2 is 3.It returns me 5.I want last query's result.That is 3 only.How to do that?
Posted
Comments
Deepak Kanswal Sharma 21-Apr-15 22:18pm    
What have you tried?
Member 11589429 22-Apr-15 1:50am    
I done with the help of @@ROWCOUNT

1 solution

Try this-
SQL
SET NOCOUNT ON
--first query
SET NOCOUNT OFF
--second query

Quote:
When SET NOCOUNT is ON, the count (indicating the number of rows affected by a Transact-SQL statement) is not returned. When SET NOCOUNT is OFF, the count is returned.
--MSDN

Hope, it helps :)
 
Share this answer
 
v2
Comments
Member 11589429 22-Apr-15 0:49am    
Even I can do with the help of @@ROWCOUNT
Herman<T>.Instance 22-Apr-15 2:06am    
my 5!
Suvendu Shekhar Giri 22-Apr-15 8:11am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900