急急急的问题!!
大家看看我的代码到底哪错了
Code:
存储过程:
ALTER PROCEDURE [dbo].[p_OPCallStatistics]
(
@operatorid INT
)
AS
IF @operatorid > 1
BEGIN
SET @conditionCC = @conditionCC +'AND OperatorsID IN (0,1)'
SET @conditionSC = @conditionSC +'AND OperatorsID IN (0,1)'
END
ELSE
BEGIN
SET @conditionCC = @conditionCC +'AND OperatorsID IN (@operatorid)'
SET @conditionSC = @conditionSC +'AND OperatorsID IN (@operatorid)'
END
主程序:
SqlParameter[] paras = new SqlParameter[]
{
new SqlParameter("@operatorid",SqlDbType.Int)
};
paras[0].Value = operatorid;
然后运行报错:
必须声明标量变量 "@operatorid"。
必须声明标量变量 "@operatorid"。
必须声明标量变量 "@operatorid"。
必须声明标量变量 "@operatorid"。
必须声明标量变量 "@operatorid"。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息:
System.Data.SqlClient.SqlException: 必须声明标量变量 "@operatorid"。
必须声明标量变量 "@operatorid"。
必须声明标量变量 "@operatorid"。
必须声明标量变量 "@operatorid"。
必须声明标量变量 "@operatorid"。
------解决方案--------------------SqlParameter[] paras = new SqlParameter[]
{
new SqlParameter("@operatorid",SqlDbType.Int)
};
paras[0].Value = operatorid;
这样写看
SqlParameter para =new SqlParameter("@operatorid",SqlDbType.Int)
para.value=operatorid;
cmd.parameters.add(para);
执行存储过程的时候默认就有个返回的参数
------解决方案--------------------ALTER PROCEDURE [dbo].[p_OPCallStatistics]
(
@operatorid INT
)
AS
declare @conditionCC nvarchar(200),@conditionSC nvarchar(200),
IF @operatorid > 1
BEGIN
SET @conditionCC = @conditionCC +'AND OperatorsID IN (0,1)'
SET @conditionSC = @conditionSC +'AND OperatorsID IN (0,1)'
END
ELSE
BEGIN
SET @conditionCC = @conditionCC +'AND OperatorsID IN (@operatorid)'
SET @conditionSC = @conditionSC +'AND
------解决方案--------------------ALTER PROCEDURE [dbo].[p_OPCallStatistics]
(
@operatorid INT
)
AS
declare @conditionCC varchar(2000)
declare @conditionSC varchar(2000)这里要申请这两个变量
IF @operatorid > 1
BEGIN
SET @conditionCC = @conditionCC +'AND OperatorsID IN (0,1)'
SET @conditionSC = @conditionSC +'AND OperatorsID IN (0,1)'
END
ELSE
BEGIN
SET @conditionCC = @conditionCC +'AND OperatorsID IN (@operatorid)'
SET @conditionSC = @conditionSC +'AND OperatorsID IN (@operatorid)'
END