Tuesday, 27 August 2013

Cannot get output from a stored procedure

Cannot get output from a stored procedure

I have a stored procedure which returns me the identity of the added row,
as below:
Create Procedure sp_ADD_CONTACT_EXTRANET_CLIENT
(
@NumCRPCEN nvarchar (255),
@nomContact nvarchar (255),
@prenomContact nvarchar (255),
@telFixe nvarchar (255),
@telPort nvarchar (255),
@mailContact nvarchar(255),
@idPhysique int output
)
as
Begin
INSERT INTO T_Physique values (.....)
SET @idPhysique = @@IDENTITY
RETURN @idPhysique
End
Now I would like to get the output in ADO.NET and I've tried a lot of
things but the last one is :
Requeteadd.Parameters.Add("@idPhysique", SqlDbType.Int).Direction =
ParameterDirection.Output;
Requeteadd.ExecuteNonQuery();
int IdPhysique = (int)Requeteadd.Parameters["@idPhysique"].Value;
But it shows me an error where it says that returned value is null. Does
anyone have an idea ?

No comments:

Post a Comment