Re: Array index



You have allocated the array for the EventTotalDS "references", but you have
not actually allocated the EventTotalDS objects themselves.

So you have allocated say 4 "slots" to hold EventTotalDS "pointers", but
each of those slots is initially empty (null).

That's why it crashes on the first index (0).

So put something like:

ET[ i ] = new EventTotalDS( );
before
ET[i].TerritoryName = dtRow["TerritoryName"].ToString();

Kevin

"Ben" <your2slow@xxxxxxxxx> wrote in message
news:1173302062.818415.169880@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am having a problem with a web service I've created getting an "
Index was outside the bounds of the array." when I try to get the
value of ET[i].TerritoryName below. I've verified the length of ET is
4 after reallocating the dynamic array and the error happens when i =
0 so the first iteration of the loop. Does anyone have any idea what
the problem is? I know it's something simple I'm just not seeing.

EventTotalDS[] ET = null;
cnn.Open();

SqlCommand cmd = new SqlCommand("BP_SREventTotals", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@p_ContactGUID", SqlDbType.UniqueIdentifier).Value
= ContactGUID;

SqlDataAdapter oDA = new SqlDataAdapter(cmd);
DataSet oDS = new DataSet();

oDA.Fill(oDS,"EventTotals");

ET = new EventTotalDS[oDS.Tables["EventTotals"].Rows.Count + 1];

int i = 0;
foreach(DataRow dtRow in oDS.Tables["EventTotals"].Rows)
{
ET[i].TerritoryName = dtRow["TerritoryName"].ToString();
//above line gets index error on the left hand side
i++;
}



.



Relevant Pages

  • Re: array lines shifting
    ... Ronen Kfir wrote: ... > how much will the lines in array move towards upwards. ... You use the first index for the columns and the second index ...
    (alt.comp.lang.learn.c-cpp)
  • Re: [PHP] mysql_fetch_array
    ... also, if you read the first line just above the first example of use, you will notice that it says that reset will return the first array element or false. ... The reason that you are getting the first column is because in your reset call, you are referencing the first index entry in your array. ... $fotos contains all records found in a db table, the SELECT statement is retrieving 2 columns from a table, how do I store all records in a 2 dimention table so I can use it later? ...
    (php.general)
  • Re: Array pointers like C++
    ... I realize that the first index of the array we want the address of, has the same address as the array itself, but why are we referring to the first index instead of the array? ... returns a pointer to a multiple dim array. ... its the same as if you don't specify any index of some kind of ...
    (comp.lang.pascal.delphi.misc)
  • Re: Array pointers like C++
    ... I realize that the first index of the array we want the address of, ... >> class var: ... > in case for some reason you don't have that TdoubleArray in the ...
    (comp.lang.pascal.delphi.misc)
  • Re: Q on the Array function...
    ... But I also go further back in history, to Fortran, before ... array as dimensionin that ancient tongue, it meant ... that its first index had 7 elements and its second index 2: ... course you were also defining its upper bound, ...
    (comp.databases.ms-access)

Loading