[英]Error in retrieving the value of the output parameter of the stored procedure
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: 我在C#代码中检索成功的值,如下所示:
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? 有人可以让我知道导致错误的原因吗?
Have you set the Parameters as below 您是否设置了如下参数
myCommand.Parameters.Add(new SqlParameter("@Success", SqlDbType.Int));
myCommand.Parameters["@Success"].Direction = ParameterDirection.Output;
Then retrieve as 然后检索为
int returnVal = (int)myCommand.Parameters["@Success"].Value;
You need to add the below code before you write the int returnVal
在编写int returnVal
之前,需要添加以下代码
myCOmmand.Parameters.Add("@Success", SqlDbType.Int).Direction = ParameterDirection.Output;
And then: 接着:
int returnVal = Convert.ToInt32(myCOmmand.Parameters["@Success"].Value);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.