开发者

indexOutofRangeException occurred

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,开发者_如何学JAVA 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();
    }

}


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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜