我想通过从 SQl 过程返回来获取值,但我收到此错误“参数计数与参数值计数不匹配”。我的代码是:
public int getControlTypeIDByVal()
{
int retVal = 0;
try
{
SqlParameter[] _param = new SqlParameter[2];
_param[0] = new SqlParameter("@ControlName2", ControlName);
_param[1] = new SqlParameter("@RetVal", SqlDbType.Int);
_param[1].Direction = ParameterDirection.ReturnValue;
SqlDataAccess.ExecuteNonQuery(SqlDataAccess.ConnectionString, "PR_getControlTypeIDByVal", _param);
if (!clsCommonFn.isNullOrEmpty(_param[1].ToString()))
{
retVal = Convert.ToInt32(_param[1]);
}
}
catch (Exception e)
{
errorMsg = e.Message;
}
return retVal;
}
和 Sp 是:-
CREATE PROCEDURE PR_getControlTypeIDByVal
@ControlName2 NVARCHAR(200)
AS
-- EXEC PR_getControlTypeIDByVal 'Jaisalmer 2N/3D'
BEGIN
DECLARE @retVal INT
SET @retVal=0
SELECT @retVal=ControlTypeID FROM ControlTypes
WHERE LTRIM(RTRIM(ControlName))=LTRIM(RTRIM(@ControlName2))
PRINT(@retVal)
RETURN @retVal
END
请帮我。
谢谢