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.
| 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 bitdeclare @YourTable table (i int)insert into @YourTable (i) values(99)if @@rowcount > 0begin set @Result = 1end elsebegin set @Result = 0endselect @Result [Result] |
 |
|
|
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.) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-24 : 12:53:20
|
| also seehttp://www.sqlteam.com/article/stored-procedures-returning-data |
 |
|
|
|
|
|