Connect with Expertise | Find Experts, Get Answers, Share Insights

@@ROWCOUNT always 0 :(

 
Join Date: Sep 2007
Posts: 26
#1: Feb 9 '10
Hi guys,

I have a weird problem - I wonder if someone could spare a second for me.

I am running a DELETE statement inside a T-SQL Stored Procedure (for my C# .NET application). It's as simple as they get.

DELETE

FROM groupPromotionRequests

WHERE groupPromotionRequestId = @requestId;

However, when I call ExecuteNonQuery() I always get back 0. I have tried...

SET NOCOUNT OFF;

...in all sorts of places inside the procedure, yet it still always returns 0. I am certain that one row will be deleted as I have ran the query inside Management Studio and it said that one row was affected, plus I have checked the table itself.

I am very familiar with this setup and have used it all over my application, but for some reason this time it just won't work. I've tried renaming the procedure, debugging the return value from ExecuteNonQuery() and rewriting the procedure but nothing appears to work.

Does anyone have any clues? Thanks for your time.

Chris

ck9663's Avatar
E
C
 
Join Date: Jun 2007
Posts: 2,250
#2: Feb 9 '10

re: @@ROWCOUNT always 0 :(


Are you asking why @@rowcount returns zero or ExecuteNonQuery() returns zero?

~~ CK
 
Join Date: Sep 2007
Posts: 26
#3: Feb 9 '10

re: @@ROWCOUNT always 0 :(


Sorry for not being so clear in the question and its title.

I am really asking for why ExecuteNonQuery() returns 0. I have run the procedure in Management Studio and have got the message '1 row affected' (this indicates that @@ROWCOUNT is indeed working). Then when I replace the single row that was deleted and try with ExecuteNonQuery(), the return is 0.
ck9663's Avatar
E
C
 
Join Date: Jun 2007
Posts: 2,250
#4: Feb 10 '10

re: @@ROWCOUNT always 0 :(


It looks like it's a C# .NET function. So you should post it to C# forum. It could be because it means no error. The 0 is a return/error code not the number of records affected.

Happy Coding!!!

~~ CK
 
Join Date: Sep 2007
Posts: 26
#5: Feb 10 '10

re: @@ROWCOUNT always 0 :(


OK, thanks for your help - i'll post it over there.

I'm not totally convinced you are correct in saying it is an error code. Please see these two pages.

http://technet.microsoft.com/en-us/l.../ms187316.aspx

http://msdn.microsoft.com/en-us/libr...enonquery.aspx
ck9663's Avatar
E
C
 
Join Date: Jun 2007
Posts: 2,250
#6: Feb 11 '10

re: @@ROWCOUNT always 0 :(


I'm sorry, am not much of a C# programmer. Check the T-SQL that you're executing. If there are two or more statement, the @@rowcount will only return the result for the last statement. Even if the last statement is just RETURN or SET statement.

Happy Coding!!!

~~ CK
Reply

Tags
delete, executenonquery, nocount