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.Parame ters["@Suc cess"].ToS tring());
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
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.Parame
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
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.