2013-04-07 59 views
0

我有一个存储过程定义为存储过程的输出参数的值如下来检查重复的电子邮件的存在:错误在检索

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 [email protected]) 
begin 
set @Success=6 
set @msg='Duplicate Email found. Please try again.'  
--Insert the records in the database 
end 
END 

我检索的值成功的C#代码如下:

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

我收到错误消息“输入值的格式不正确”。

有人能让我知道是什么导致了错误?

回答

1

你有设置参数如下

myCommand.Parameters.Add(new SqlParameter("@Success", SqlDbType.Int)); 
myCommand.Parameters["@Success"].Direction = ParameterDirection.Output; 

然后检索作为

int returnVal = (int)myCommand.Parameters["@Success"].Value; 
0

您需要添加下面的代码你写的int returnVal

myCOmmand.Parameters.Add("@Success", SqlDbType.Int).Direction = ParameterDirection.Output; 

然后之前:

int returnVal = Convert.ToInt32(myCOmmand.Parameters["@Success"].Value);