Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6722255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:25:32+00:00 2026-05-26T09:25:32+00:00

I am getting indexoutofrangeexception (see —-> pointer for the line generating the error down

  • 0

I am getting indexoutofrangeexception (see —-> pointer for the line generating the error down below in the code). The program loops through the header and line item records in a dataset tables. The tables have a relationship. My sample data has 2 headers, each with 2 lines. The progam has two loops, the first one loops through the header records and the second one loops through the child records of the header.

Part of the program:

     // ***** PO Header and Line 

        int ln;
        ln = 0;

        // Create an eConnect PO Header node object
        taGLTransactionHeaderInsert jeh = new taGLTransactionHeaderInsert();

        // Create an array for lineitems
        taGLTransactionLineInsert_ItemsTaGLTransactionLineInsert[] lineitems = new   taGLTransactionLineInsert_ItemsTaGLTransactionLineInsert[ln];

        foreach (DataRow dtrHDR in ds.Tables["Header"].Rows)

        {
            Array.Clear(lineitems, 0, ln);

            jeh.BACHNUMB = "Sheraz";
            jeh.JRNENTRY = jenoint;
            jeh.REFRENCE = dtrHDR["Reference"].ToString();
            jeh.SOURCDOC = dtrHDR["AvantisJE"].ToString();
            jeh.USERID = System.Environment.UserName;
            jeh.TRXDATE = System.DateTime.Now.ToString();

            ln = 0;

            foreach (DataRow dtrLine in dtrHDR.GetChildRows("HdrLine"))

            {

                // Populate the elements of the taPoLIne_ItemsTaPOLine XML node
                taGLTransactionLineInsert_ItemsTaGLTransactionLineInsert jel = new taGLTransactionLineInsert_ItemsTaGLTransactionLineInsert();

                jel.BACHNUMB = jeh.BACHNUMB;
                jel.JRNENTRY = jeh.JRNENTRY;
                jel.ACTNUMST = dtrLine["GreatPlains"].ToString();
                jel.DEBITAMT = Convert.ToDecimal(dtrLine["Debit"].ToString());

                //Avantis Inv Trx Key
                jel.ORDOCNUM = dtrLine["AvantisJE_Line"].ToString();
                // Avantis GL Trx Type
                jel.ORTRXDESC = dtrLine["transactiontypename"].ToString();


                //Add POLine to an Array
                lineitems[ln] = jel;     ----------------> I get an error here!

                ln = ln + 1;

                Array.Resize(ref lineitems, ln + 1);

            }

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:25:33+00:00Added an answer on May 26, 2026 at 9:25 am

    You are accessing an index that doesn’t yet exist.

    //Add POLine to an Array
    lineitems[ln] = jel;     ----------------> I get an error here!
    ln = ln + 1;     
    Array.Resize(ref lineitems, ln + 1);
    

    You need to change the order to :

    //Add POLine to an Array
    Array.Resize(ref lineitems, ln + 1);
    lineitems[ln] = jel;     ----------------> should be fixed, no error here!
    ln = ln + 1;     
    

    EDIT: Now that the immediate problem is out of the way, on to a better implementation.

    Arrays are of a fixed sized, resizing an array is an expensive operation (basically it entails creating a copy with a new size). typically you would use these after identifying a performance bottle neck. In most cases it would be much better to use a List.

    I’d recommend changing this line:

    // Create an array for lineitems
    taGLTransactionLineInsert_ItemsTaGLTransactionLineInsert[] lineitems = 
                  new    taGLTransactionLineInsert_ItemsTaGLTransactionLineInsert[ln];
    

    to:

    var lineitems = new  List<taGLTransactionLineInsert_ItemsTaGLTransactionLineInsert>();
    

    and then to add to it you simply do

    lineitems.Add(jel);
    

    to iterate over them would be:

    for (var ln in lineitems) {
     // whatever you want to do with a line.
    }
    

    to acccess a specific item by index would be:

    lineitems.Item(i); // get the ith item in the list.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the continuous error of IndexOutOfRangeException in my c# code. The code
I am getting 'indexOutofRangeException occurred' error - 'FixedActual' this is the code i am
Getting the above error in following code. How to rectify it. Thanks. Please look
I am getting an IndexOutOfRange exception on the following line of code: var searchLastCriteria
Getting the following error: "Warning: Cannot modify header information - headers already sent by
Getting this error while trying to compile a copied code from a Fortran 77
Getting the (hex) error code from an IOException, or regular Exception! Is this possible?
Getting this error when running pip install -U selenium . Mid way through the
Getting this error: 2009-09-03 12:44:02.307 xcodebuild[307:10b] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler
Getting a rendering error for this form: 'NoneType' object has no attribute 'widget' http://dpaste.com/88585/

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.