Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Return rows affected from stored procedure

Author  Topic 

Ironwil
Starting Member

8 Posts

Posted - 2009-06-23 : 18:56:27
I'm working in C#, calling a stored procedure to insert a new user into a DB. I need to know if the insert was successful, so I'm trying to return the affected rows to the calling code. I read a bit about using @@ROWCOUNT, but the examples I saw only had it print out something if the count wasn't greater than zero, which doesn't help.

nathans
Aged Yak Warrior

938 Posts

Posted - 2009-06-23 : 19:49:48
Why not just do the check for rows affected at the db level and return a success/failure bit to the app?


declare @Result bit
declare @YourTable table (i int)


insert into @YourTable (i)
values(99)
if @@rowcount > 0
begin
set @Result = 1
end else
begin
set @Result = 0
end

select @Result [Result]
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2009-06-23 : 19:52:19
Or, if you have a predefined convention re: Return Codes between app and db then you can just return an error indicator there as well (-1, etc.)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-24 : 12:53:20
also see

http://www.sqlteam.com/article/stored-procedures-returning-data
Go to Top of Page
   

- Advertisement -