gpt4 book ai didi

c# - 参数的数量与存储过程的值的数量不匹配

转载 作者:行者123 更新时间:2023-11-30 16:27:26 29 4
gpt4 key购买 nike

我正在使用 Enterprise Library 5x DAAB 调用带有一个输入参数和一个输出参数的 Oracle 存储过程。但它给出了这个错误:

The number of parameters does not match number of values for stored procedure

我的代码如下:

OracleDatabase _database;
OracleConnection _connection;
...
...
DbCommand insertCommand = _database.GetStoredProcCommand("spName");
insertCommand.Connection = _connection;
_database.AddInParameter(insertCommand, "inParam", DbType.Int16);
_database.AddOutParameter(insertCommand, "outParam", DbType.Byte, 1);
insertCommand.Prepare();

object[] paramValues = new object[] { 1, 2 };
_database.AssignParameters(insertCommand, paramValues);
_database.ExecuteNonQuery(insertCommand, _transaction);
int outParamVal = (int)_database.GetParameterValue(insertCommand, "outParam");

请注意:以上代码是完整源代码的一个小型示例。但描述了类似的功能。

这是我正在使用的 SP:

create or replace
PROCEDURE SP_APPEND_TO_PRICE_TRANSFER
(
FISCAL_YEAR IN NUMBER
, FISCAL_MONTH IN NUMBER
, PRODUCT_ID IN NUMBER
, RD_MARKUP IN NUMBER
, RD_RETAIL_PRICE IN NUMBER
, BL_MARKUP IN NUMBER
, BL_RETAIL_PRICE IN NUMBER
, RD_SPEC_FLAG IN VARCHAR2
, BL_SPEC_FLAG IN VARCHAR2
, LEMONADE_DISTRIB_PRICE IN NUMBER
, AFS_DISTRIB_PRICE IN NUMBER
, GLAZIER_DISTRIB_PRICE IN NUMBER
, GLAZIER_DISTRIB_CASE_PRICE IN NUMBER
, SARALEE1_DISTRIB_PRICE IN NUMBER
, SARALEE1_DISTRIB_CASE_PRICE IN NUMBER
, CAROLINA_DISTRIB_PRICE IN NUMBER
, NETUNITCOST IN NUMBER
, RD_INTERNAL_MARKUP IN NUMBER
, BL_INTERNAL_MARKUP IN NUMBER
, RD_TRANSFER_COST IN NUMBER
, BL_TRANSFER_COST IN NUMBER
, TOTAL_NET_WEIGHT IN NUMBER
, PRICE_TRANSFER_UOM IN VARCHAR2
, STD_PACK IN NUMBER
, PAGE_LOCATION_CODE IN VARCHAR2
, PPOD1_DISTRIB_PRICE IN NUMBER
, PPOD1_DISTRIB_CASE_PRICE IN NUMBER
, PPOD1_STOCK_FLAG IN VARCHAR2
, SLASHOUT_PRICE_RD IN NUMBER
, SLASHOUT_PRICE_BL IN NUMBER
, ROWSINSRTD OUT NUMBER
) AS
BEGIN
INSERT INTO PRICE_TRANSFER (
FISCAL_YEAR,
FISCAL_MONTH,
PRODUCT_ID,
CHI_REBATE_PCT,
CHI_RETAIL_PRICE,
NE_REBATE_PCT,
NE_RETAIL_PRICE,
CHI_SPEC_FLAG,
NE_SPEC_FLAG,
LEMONADE_DISTRIB_PRICE,
AFS_DISTRIB_PRICE,
GLAZIER_DISTRIB_PRICE,
GLAZIER_DISTRIB_CASE_PRICE,
SARALEE1_DISTRIB_PRICE,
SARALEE1_DISTRIB_CASE_PRICE,
CAROLINA_DISTRIB_PRICE,
NETUNITCOST,
CHI_INTERNAL_MARKUP,
NE_INTERNAL_MARKUP,
CHI_TRANSFER_COST,
NE_TRANSFER_COST,
TOTAL_NET_WEIGHT,
PRICE_TRANSFER_UOM,
CASE_PACK_FACTOR,
PAGE_LOCATION_CODE,
PPOD1_DISTRIB_PRICE,
PPOD1_DISTRIB_CASE_PRICE,
PPOD1_STOCK_FLAG,
SLASHOUT_PRICE_RD,
SLASHOUT_PRICE_BL )
VALUES (
FISCAL_YEAR
, FISCAL_MONTH
, PRODUCT_ID
, RD_MARKUP
, RD_RETAIL_PRICE
, BL_MARKUP
, BL_RETAIL_PRICE
, RD_SPEC_FLAG
, BL_SPEC_FLAG
, LEMONADE_DISTRIB_PRICE
, AFS_DISTRIB_PRICE
, GLAZIER_DISTRIB_PRICE
, GLAZIER_DISTRIB_CASE_PRICE
, SARALEE1_DISTRIB_PRICE
, SARALEE1_DISTRIB_CASE_PRICE
, CAROLINA_DISTRIB_PRICE
, NETUNITCOST
, RD_INTERNAL_MARKUP
, BL_INTERNAL_MARKUP
, RD_TRANSFER_COST
, BL_TRANSFER_COST
, TOTAL_NET_WEIGHT
, PRICE_TRANSFER_UOM
, STD_PACK
, PAGE_LOCATION_CODE
, PPOD1_DISTRIB_PRICE
, PPOD1_DISTRIB_CASE_PRICE
, PPOD1_STOCK_FLAG
, SLASHOUT_PRICE_RD
, SLASHOUT_PRICE_BL );

ROWSINSRTD := sql%rowcount;
END SP_APPEND_TO_PRICE_TRANSFER;

2011-11-02
所以,目前似乎没有解决方案。所以暂时,我通过以下方式完成了我的工作。非常基本的东西..

...
...
OracleConnection _connection = _dbConnect.OpenOracleDB(); //custom API to get the Connection object
OracleTransaction transaction = _connection.BeginTransaction();
int affectedRows = 0;
OracleCommand insertCommand = new OracleCommand("MyProc", _connection, transaction);
using (insertCommand)
{
insertCommand.CommandType = CommandType.StoredProcedure;
OracleParameter param1 = new OracleParameter("PARAM1", OracleType.Number);
param1.Direction = ParameterDirection.Input;
insertCommand.Parameters.Add(param1);
OracleParameter param2 = new OracleParameter("PARAM2", OracleType.Number);
param2.Direction = ParameterDirection.Input;
insertCommand.Parameters.Add(param2);
OracleParameter outParam = new OracleParameter("OUTPARAM", OracleType.Int32);
outParam.Size = 1;
outParam.Direction = ParameterDirection.Output;
insertCommand.Parameters.Add(outParam);

insertCommand.Prepare();

foreach (MyObject myObject in myObjects) //myObjects is a list of objects I want to persist
{
param1.Value = myObject.Prop1;
param2.Value = myObject.Prop2;

insertCommand.ExecuteNonQuery();
affectedRows = Convert.ToInt32(outParam.Value);
}

transaction.Commit();
}
...
...

最佳答案

据我统计,您的存储过程有 30 个输入参数和 1 个输出参数。如果你想让它运行,你将需要提供你的过程需要的所有 30 个输入参数。

关于c# - 参数的数量与存储过程的值的数量不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7917145/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com