我有一個存儲過程如下:與OUT參數的存儲過程
ALTER PROCEDURE [dbo].[sp_CheckEmailAvailability] -- Add the
parameters for the stored procedure here (@Email VARCHAR(50)=null,
@Count 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 @Count=COUNT(*) from dbo.tx_UserPersonalDetails where [email protected]
END
我在我的aspx.cs頁面下面的代碼: -
SqlCommand cmd = new SqlCommand("[dbo].[sp_CheckEmailAvailability]", objcon);
int result = 0;
try
{
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter parm = new SqlParameter("@Email", SqlDbType.VarChar);
parm.Value = txtUserName.Text.ToString();
parm.Direction = ParameterDirection.Input;
cmd.Parameters.Add(parm);
SqlParameter parm1 = new SqlParameter("@Count", SqlDbType.Int);
// parm1.Value = txtUserName.Text.ToString();
parm.Direction = ParameterDirection.Output;
cmd.Parameters.Add(parm1);
cmd.Connection.Open();
result=cmd.ExecuteNonQuery();
if (result>0)
{
lblAvailText.Text = "Email id is in use";
}
else
{
lblAvailText.Text = "Email id is Available";
}
}
catch (SqlException sql)
{
}
finally
{
cmd.Connection.Close();
}
當我運行代碼,我出現以下錯誤: -
正式參數「@Email」未聲明爲OUTPUT參數 ,但傳入的實際參數要求的輸出。
請幫我一把。
你使用了太多的複製/粘貼,並在你的變量名犯了一個錯誤的第二個參數方向。 – Oded