先排除存储过程的问题,已测试,没有问题!
这是
public SqlParameter[] ProduceSuggestParameters
{
get
{
SqlParameter[] parms = new SqlParameter[8];
//@MRPCalID varchar(25),--MRP运算编码
//@MPSID varchar(25),--主生产计划编码
//@ProductID varchar(50),--产品型号
//@ProduceNum decimal(12,2),--计划生产数量
//@PlanStartDate smalldatetime,--计划生产日期
//@PlanFinishDate smalldatetime,--计划完工日期
//@IsAdvWasteRate bit = 1--是否考虑报废率
//@IsAdvProduceKalendar bit = 1--是否考虑车间生产工作日
parms[0] = new SqlParameter(P_MRPCalID, SqlDbType.VarChar, 25);
parms[0].Value = this.MRPCalID;
parms[1] = new SqlParameter(P_MPSID, SqlDbType.VarChar, 25);
parms[2] = new SqlParameter(P_ProductID, SqlDbType.VarChar, 50);
parms[3] = new SqlParameter(P_ProduceNum, SqlDbType.Decimal);
parms[4] = new SqlParameter(P_PlanStartDate, SqlDbType.SmallDateTime);
parms[5] = new SqlParameter(P_PlanFinishDate, SqlDbType.SmallDateTime);
parms[6] = new SqlParameter(P_IsAdvWasteRate, SqlDbType.Bit);
parms[6].Value = this.MRPCalOptions.IsAdvWasteRate;
parms[7] = new SqlParameter(P_IsAdvProduceKalendar, SqlDbType.Bit);
parms[7].Value = this.MRPCalOptions.IsAdvProduceKalendar;
return parms;
}
}
调用过程:
waitDialog.SetStatusInfo(string.Format("开始创建产品:{0}的生产建议...", ProductID));
cmd = CommandBase.CreateCommand(CreateProduceSP);
using (cmd)
{
cmd.CommandType = CommandType.StoredProcedure;
//cmd.Parameters.Clear();
cmd.Parameters.AddRange(ProduceSuggestParms);//生产建议参数
cmd.Parameters[P_MPSID].Value = MPSID;
cmd.Parameters[P_ProductID].Value = ProductID;
cmd.Parameters[P_ProduceNum].Value = MPSNum;
cmd.Parameters[P_PlanStartDate].Value = dtMPS.Rows[i][PlanStartDate];
cmd.Parameters[P_PlanFinishDate].Value = dtMPS.Rows[i][PlanFinishDate];
int count = cmd.ExecuteNonQuery();
////到这里出现错误:"另一个 SqlParameterCollection 中已包含 SqlParameter。",但检测过都没问题啊!
waitDialog.SetStatusInfo("共创建了 " + count.ToString() + " 条生产加工建议 + 警告信息!");
}
[此贴子已经被作者于2007-6-2 19:51:35编辑过]