By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,856 Members | 2,163 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,856 IT Pros & Developers. It's quick & easy.

@@ROWCOUNT always 0 :(

P: 26
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
Feb 9 '10 #1
Share this Question
Share on Google+
5 Replies


ck9663
Expert 2.5K+
P: 2,878
Are you asking why @@rowcount returns zero or ExecuteNonQuery() returns zero?

~~ CK
Feb 9 '10 #2

P: 26
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.
Feb 10 '10 #3

ck9663
Expert 2.5K+
P: 2,878
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
Feb 10 '10 #4

P: 26
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
Feb 10 '10 #5

ck9663
Expert 2.5K+
P: 2,878
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
Feb 11 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.