发生indexOutofRangeException

发布于 2024-09-26 22:17:41 字数 2958 浏览 1 评论 0原文

我收到“发生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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

像极了他 2024-10-03 22:17:41

嗯,异常意味着您的 SqlDataReader 没有 FixedActual 列。老实说,这就是我们从你所展示的内容中真正能看出的一切。我们不知道您的 SalesGetRecalcOrderItemCosts 存储过程的用途,但它似乎没有完全返回您所期望的结果。

您可能想在调试器中查看 SqlDataReader 并查看哪些字段可用。

(顺便说一句,您应该对这些资源(命令、阅读器等)使用 using 语句,以便正确处理所有内容。也不清楚为什么要使用完全限定的类型名称在某些地方,但在其他地方则不然。)

Well, the exception means your SqlDataReader doesn't have a FixedActual column. That's all we can really tell from what you've shown, to be honest. We don't know what your SalesGetRecalcOrderItemCosts 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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文