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 |
just.net
Starting Member
24 Posts |
Posted - 2009-04-05 : 10:02:40
|
hello,how can i return an integer from stored?i create a:ALTER PROCEDURE [dbo].[sp_deleteVaccination] @vacID intASDECLARE @result intBEGIN IF(EXISTS(SELECT VaccinationTypeID FROM dbo.Vaccinations WHERE VaccinationTypeID = @vacID )) BEGIN SET @result = 0 END ELSE BEGIN DELETE FROM dbo.VaccinationsTypes WHERE ID = @vacID SET @result = 1 END RETURN @resultENDI just wanted to check if the foreign key is in useand then delete/not delete and return a flag.in the c# code i create a typed DS andthis stored is working fine and do the work, except the factthat it always return null value instead of int.(only in C# its return null)what could be the problem? |
|
just.net
Starting Member
24 Posts |
Posted - 2009-04-05 : 10:56:34
|
I found the solution:ALTER PROCEDURE [dbo].[sp_deleteVaccination] @vacID intASDECLARE @result intBEGIN IF(EXISTS(SELECT VaccinationTypeID FROM dbo.Vaccinations WHERE VaccinationTypeID = @vacID)) BEGIN SET @result = 0 END ELSE BEGIN DELETE FROM dbo.VaccinationsTypes WHERE ID = @vacID SET @result = 1 END SELECT @result AS ResultEND |
 |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2009-04-05 : 10:58:34
|
Looking at your stored procedure, unless there is an exception, @result should be set to 0 or 1. If that is the case, and if your C# code is not receiving that value, the problem is in the C# code, not in the stored procedure.What the problem is depends on what method you are using. If you are using ADO.Net, make sure you add the return value parameter, and set the direction of the value with a statement such as RetVal.Direction = ParameterDirection.ReturnValue If you google for it, you will find examples. |
 |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2009-04-05 : 11:02:59
|
quote: Originally posted by just.net SELECT @result AS ResultEND
Then, I guess you were trying to get the data from the record set returned via an ExecuteScalar or ExecuteReader. I assumed you were trying to get the result in a parameter. |
 |
|
just.net
Starting Member
24 Posts |
Posted - 2009-05-07 : 15:11:20
|
yes i want that the SP will return Integer as a type,the SP return a number as an object, then i am converting theobject to integer. can i return actualy int? |
 |
|
|
|
|
|
|