Re: Array index
- From: "Kevin Frey" <kevin_g_frey@xxxxxxxxxxx>
- Date: Thu, 8 Mar 2007 08:35:29 +1100
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++;
}
.
- Follow-Ups:
- Re: Array index
- From: Ben
- Re: Array index
- References:
- Array index
- From: Ben
- Array index
- Prev by Date: Re: struct ToString() not automatically invoked
- Next by Date: Re: Set DEBUG flag at runtime?
- Previous by thread: Array index
- Next by thread: Re: Array index
- Index(es):
Relevant Pages
|
Loading