Link to home
Start Free TrialLog in
Avatar of Aravind Ranganathan
Aravind Ranganathan

asked on

Index was outside the bounds of the array

i have a datatable called onlynewwithstatuschange
 DataTable onlynewwithstatuschange = new DataTable();
            onlynewwithstatuschange.Columns.Add("CUSTOMER", typeof(string));
            onlynewwithstatuschange.Columns.Add("NAME", typeof(string));
            onlynewwithstatuschange.Columns.Add("ADDRESS", typeof(string));
            onlynewwithstatuschange.Columns.Add("ADDRESS 2", typeof(string));
            onlynewwithstatuschange.Columns.Add("CITY", typeof(string));
            onlynewwithstatuschange.Columns.Add("STATE", typeof(string));
            onlynewwithstatuschange.Columns.Add("ZIP CODE", typeof(string));
            onlynewwithstatuschange.Columns.Add("PARENT", typeof(string));
            onlynewwithstatuschange.Columns.Add("TELEPHONE", typeof(string));
            onlynewwithstatuschange.Columns.Add("FAX", typeof(string));
            onlynewwithstatuschange.Columns.Add("TERMS OF PAYMENT", typeof(string));
            onlynewwithstatuschange.Columns.Add("COUNTRY", typeof(string));
            onlynewwithstatuschange.Columns.Add("CURRENCY", typeof(string));
            onlynewwithstatuschange.Columns.Add("STATUS", typeof(string));
            onlynewwithstatuschange.Columns.Add("STATUS CHANGED", typeof(string));
            onlynewwithstatuschange.Columns.Add("LONG", typeof(string));
            onlynewwithstatuschange.Columns.Add("LAT", typeof(string));
            onlynewwithstatuschange.Columns.Add("TAXID", typeof(string));

Open in new window


i am doing a status change check earlier in the code and adding those values to another datatable called tempchange.

then running the following code:
foreach (DataRow temp in tempchange.Rows)
            {
                DataRow[] foundRows = c.Select("CUSTOMER = '" + temp["CUSTOMER"].ToString().Trim() + "'");
                if (foundRows.Length != 0)
                {
                    onlynewwithstatuschange.Rows.Add(foundRows[0].ToString(), foundRows[1].ToString().Trim(), foundRows[2].ToString().Trim(), foundRows[3].ToString().Trim(), foundRows[4].ToString().Trim(), foundRows[5].ToString().Trim(), foundRows[6].ToString().Trim(), foundRows[7].ToString().Trim(), foundRows[8].ToString().Trim(), foundRows[9].ToString().Trim(), foundRows[10].ToString().Trim(), foundRows[11].ToString().Trim(), foundRows[12].ToString().Trim(), foundRows[13].ToString().Trim(),[b] temp[1].ToString()[/b] - getting from the temp change table so the use can see the status was changed from what, foundRows[14].ToString().Trim(), foundRows[15].ToString().Trim(), foundRows[16].ToString().Trim());
          }
            }

Open in new window


i counted the array and there are 17 values present and including the temp[1] it comes to a total of 18 values and the onlynewstatuschange datatable  has 18 columns so why then am i getting the index was outside the bounds of the array error?
ASKER CERTIFIED SOLUTION
Avatar of Snarf0001
Snarf0001
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aravind Ranganathan
Aravind Ranganathan

ASKER

Thanks mate i didnt know it needed another indexer