发生indexOutofRangeException
我收到“发生indexOutofRangeException”错误-“FixedActual”
这是我正在使用的代码,任何帮助都会被占用。
SqlDataReader dataReader = null;
SqlCommand Scmd = new SqlCommand("SalesGetRecalcOrderItemCosts", this._connection);
Scmd.CommandType = System.Data.CommandType.StoredProcedure;
Scmd.Transaction = currentTransaction;
Scmd.Parameters.AddWithValue("@OrderNumber", ItemSODBOM.SONO); //SoItem.fSnoNo
Scmd.Parameters.AddWithValue("@UTCompFCostRef", sUTCompFCostRef);//utcomp.fcostref
Scmd.Parameters.AddWithValue("@UTCompFCostEst", sUTCompFCostEst);//utcomp.fcostest
Scmd.Parameters.AddWithValue("@UTCompFCostMType", sUTCompFCostMType);//utcomp.fcostmtype
Scmd.Parameters.AddWithValue("@OrderItemNumber", finumber); //SoItem.finumber
Scmd.Parameters.AddWithValue("@OrderType", "S");//Sales Order
Scmd.Parameters.AddWithValue("@UseStandardTransitCost", "0");
Scmd.Parameters.AddWithValue("@GetExtendedCosts", "0");
dataReader = Scmd.ExecuteReader();
while (dataReader.Read())
{
using (System.Data.SqlClient.SqlCommand updateCommand = this._connection.CreateCommand())
{
string sql = @"
UPDATE SOITEM SET
FFIXACT = @FixedActual, FLABACT = @LaborActual, FMATLACT = @MaterialActual,
FOTHRACT = @OtherActual, FOVHDACT= @OverheadActual, FRTGSETUPA= @SetupActual,
FSUBACT = @SubcontractActual, FTOOLACT = @ToolActual,FSTANDPART = 0,
FTOTPTIME = @TotalPTime, FTOTSTIME = @TotalSTime, FULABCOST1 = @ULaborCost1
WHERE FSONO = @FSONO and FINUMBER = @FINUM
";
updateCommand.CommandText = sql;
updateCommand.CommandType = System.Data.CommandType.Text;
updateCommand.Transaction = currentTransaction;
updateCommand.Parameters.AddWithValue("@FixedActual", dataReader["FixedActual"]); //This is where i am getting error
updateCommand.Parameters.AddWithValue("@LaborActual", dataReader["LaborActual"]);
updateCommand.Parameters.AddWithValue("@MaterialActual", dataReader["MaterialActual"]);
updateCommand.Parameters.AddWithValue("@OtherActual", dataReader["OtherActual"]);
updateCommand.Parameters.AddWithValue("@OverheadActual", dataReader["OverheadActual"]);
updateCommand.Parameters.AddWithValue("@SetupActual", dataReader["SetupActual"]);
updateCommand.Parameters.AddWithValue("@SubcontractActual", dataReader["SubcontractActual"]);
updateCommand.Parameters.AddWithValue("@ToolActual", dataReader["ToolActual"]);
updateCommand.Parameters.AddWithValue("@TotalPTime", dataReader["TotalPTime"]);
updateCommand.Parameters.AddWithValue("@TotalSTime", dataReader["TotalSTime"]);
updateCommand.Parameters.AddWithValue("@ULaborCost1", dataReader["ULaborCost1"]);
updateCommand.Parameters.AddWithValue("@FSONO", ItemSODBOM.SONO);
updateCommand.Parameters.AddWithValue("@FINUM", finumber);
updateCommand.ExecuteNonQuery();
}
}
I am getting 'indexOutofRangeException occurred' error - 'FixedActual'
this is the code i am using any help would be appropriated.
SqlDataReader dataReader = null;
SqlCommand Scmd = new SqlCommand("SalesGetRecalcOrderItemCosts", this._connection);
Scmd.CommandType = System.Data.CommandType.StoredProcedure;
Scmd.Transaction = currentTransaction;
Scmd.Parameters.AddWithValue("@OrderNumber", ItemSODBOM.SONO); //SoItem.fSnoNo
Scmd.Parameters.AddWithValue("@UTCompFCostRef", sUTCompFCostRef);//utcomp.fcostref
Scmd.Parameters.AddWithValue("@UTCompFCostEst", sUTCompFCostEst);//utcomp.fcostest
Scmd.Parameters.AddWithValue("@UTCompFCostMType", sUTCompFCostMType);//utcomp.fcostmtype
Scmd.Parameters.AddWithValue("@OrderItemNumber", finumber); //SoItem.finumber
Scmd.Parameters.AddWithValue("@OrderType", "S");//Sales Order
Scmd.Parameters.AddWithValue("@UseStandardTransitCost", "0");
Scmd.Parameters.AddWithValue("@GetExtendedCosts", "0");
dataReader = Scmd.ExecuteReader();
while (dataReader.Read())
{
using (System.Data.SqlClient.SqlCommand updateCommand = this._connection.CreateCommand())
{
string sql = @"
UPDATE SOITEM SET
FFIXACT = @FixedActual, FLABACT = @LaborActual, FMATLACT = @MaterialActual,
FOTHRACT = @OtherActual, FOVHDACT= @OverheadActual, FRTGSETUPA= @SetupActual,
FSUBACT = @SubcontractActual, FTOOLACT = @ToolActual,FSTANDPART = 0,
FTOTPTIME = @TotalPTime, FTOTSTIME = @TotalSTime, FULABCOST1 = @ULaborCost1
WHERE FSONO = @FSONO and FINUMBER = @FINUM
";
updateCommand.CommandText = sql;
updateCommand.CommandType = System.Data.CommandType.Text;
updateCommand.Transaction = currentTransaction;
updateCommand.Parameters.AddWithValue("@FixedActual", dataReader["FixedActual"]); //This is where i am getting error
updateCommand.Parameters.AddWithValue("@LaborActual", dataReader["LaborActual"]);
updateCommand.Parameters.AddWithValue("@MaterialActual", dataReader["MaterialActual"]);
updateCommand.Parameters.AddWithValue("@OtherActual", dataReader["OtherActual"]);
updateCommand.Parameters.AddWithValue("@OverheadActual", dataReader["OverheadActual"]);
updateCommand.Parameters.AddWithValue("@SetupActual", dataReader["SetupActual"]);
updateCommand.Parameters.AddWithValue("@SubcontractActual", dataReader["SubcontractActual"]);
updateCommand.Parameters.AddWithValue("@ToolActual", dataReader["ToolActual"]);
updateCommand.Parameters.AddWithValue("@TotalPTime", dataReader["TotalPTime"]);
updateCommand.Parameters.AddWithValue("@TotalSTime", dataReader["TotalSTime"]);
updateCommand.Parameters.AddWithValue("@ULaborCost1", dataReader["ULaborCost1"]);
updateCommand.Parameters.AddWithValue("@FSONO", ItemSODBOM.SONO);
updateCommand.Parameters.AddWithValue("@FINUM", finumber);
updateCommand.ExecuteNonQuery();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,异常意味着您的
SqlDataReader
没有FixedActual
列。老实说,这就是我们从你所展示的内容中真正能看出的一切。我们不知道您的SalesGetRecalcOrderItemCosts
存储过程的用途,但它似乎没有完全返回您所期望的结果。您可能想在调试器中查看
SqlDataReader
并查看哪些字段可用。(顺便说一句,您应该对这些资源(命令、阅读器等)使用
using
语句,以便正确处理所有内容。也不清楚为什么要使用完全限定的类型名称在某些地方,但在其他地方则不然。)Well, the exception means your
SqlDataReader
doesn't have aFixedActual
column. That's all we can really tell from what you've shown, to be honest. We don't know what yourSalesGetRecalcOrderItemCosts
stored procedure does, but it appears not to be returning exactly what you expect.You might want to look at the
SqlDataReader
in a debugger and see what fields are available.(As an aside, you should be using
using
statements for these resources - the command, reader etc - so that you dispose of everything properly. It's also not clear why you're using fully-qualified type names in some places but not others.)