我試圖從C#中的存儲過程獲取返回值,但它總是返回{}。我的代碼如下:從存儲過程獲取返回值
SqlCommand cmd = new SqlCommand ();
cmd.CommandText = "EXEC dbo.verifyEmailDomain @Domain, @RESULT";
cmd.Connection = con;
SqlParameter domain_p = new SqlParameter ("@Domain", SqlDbType.NVarChar);
domain_p.Value = domain;
cmd.Parameters.Add (domain_p);
SqlParameter ret = new SqlParameter("@RESULT", SqlDbType.Int);
ret.Direction = ParameterDirection.Output;
cmd.Parameters.Add (ret);
con.Open ();
cmd.ExecuteNonQuery ();
var value = cmd.Parameters ["@RESULT"].Value;
con.Close ();
我也試圖設置 「ret.Direction = ParamaterDirection.ReturnValue」 無濟於事
存儲過程如下:
ALTER PROCEDURE [dbo].[verifyEmailDomain]
-- Add the parameters for the stored procedure here
@Domain nvarchar(200),
@RESULT INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT @RESULT = COUNT(*)
FROM Josh.dbo.refDomains
WHERE LOWER(EMAIL_DOMAIN)=LOWER(@Domain)
RETURN @RESULT
END
我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 – 2014-11-24 17:04:44