2013-04-07 60 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);