Link to home
Create AccountLog in
Avatar of deoyagya
deoyagya

asked on

Error when retrieving the values of output parameter of a stored procedure

Hi,

I have a stored procedure defined as follows to check the existence of the duplicate Email:

USE [SQL2008_850994_onebizness]
GO
/****** Object:  StoredProcedure [dbo].[EmailExists]    Script Date: 04/07/2013 15:14:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 
ALTER PROCEDURE [dbo].[EmailExists]
@EmailID Nvarchar(50),
@Success int output,
@msg varchar(50) output  
 
AS
BEGIN
IF EXISTS(SELECT 1 FROM dbo.Membership WHERE EmailId = @emailID)
    OR EXISTS(SELECT 1 FROM dbo.Allocation where ResourceEmail=@emailID)
begin
set @Success=6
set @msg='Duplicate Email found. Please try again.'      
--Insert the records in the database
end
END

--------------------------------------------------------------

I am retrieving the value of the success in a C# code as follows:

int returnVal = int.Parse(myCOmmand.Parameters["@Success"].ToString());


I am getting the error message "Input values are not in the correct format".

Can someone please let me know what is causing the error?

Thanks for the help.
Yagya
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

Your stored procedure needs to return values if there is no duplicate as well. The error is most likely due to the output parameters returning as null and the int.parse errors as it cannot convert a null into an integer.
ASKER CERTIFIED SOLUTION
Avatar of rajeeshmca
rajeeshmca
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer