Array index



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 index
    ... You have allocated the array for the EventTotalDS "references", ... not actually allocated the EventTotalDS objects themselves. ... That's why it crashes on the first index. ... //above line gets index error on the left hand side ...
    (microsoft.public.dotnet.languages.csharp)
  • (patch for Bash) regex case statement
    ... Following up on my previous patch for regex conditional tests, ... /* Return an array of strings; ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
    (comp.unix.shell)
  • Re: Strategy or Iterator?
    ... It would be possible to write a class that returns the variations ... GNU General Public License for more details. ... protected CombinatoricOperator(Telements, int r) { ... An integer array backing up the original one to keep track of the ...
    (comp.lang.java.programmer)
  • (patch for Bash) regex conditional tests
    ... 'regex' are returned in array variable SUBMATCH. ... Skipping of positional parameters, array elements, string ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
    (comp.unix.shell)
  • Re: Warning on assigning a function-returning-a-pointer-to-arrays
    ... This declares pfunc as a function taking no arguments and returning ... int x, y; ... Presumably pfuncwill return a pointer to a single int, ... or the first of a sequence of "array 5 of int"s. ...
    (comp.lang.c)