Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Index out of range - I don't think so...

Status
Not open for further replies.

TheDust

Programmer
Aug 12, 2002
217
US
I'm having trouble with something relatively simple here... (but I'm new with ASP.NET so forgive me).

I'm defining an ArrayList named "teamMemberIds", then going through a database table, pulling certain values out, and placing them in the ArrayList. I define the integer "numberOfWorkers" simply to place the values I pull out of the database in an increasing index number starting at "0".

PAGE: CODE:

ArrayList teamMemberIds = new ArrayList();
int numberOfWorkers = 0;
for (int z = 0; z < tableTeamMembersTasks.Rows.Count; z++) {
if (Convert.ToInt32(tableTeamMembersTasks.Rows[z][&quot;taskID&quot;]) == taskIDNumber) {
teamMemberIds[numberOfWorkers] = Convert.ToInt32(tableTeamMembersTasks.Rows[x][&quot;taskID&quot;]);
numberOfWorkers++;
}
}

Maybe my syntax is wrong here, but it's giving me the error that the index I'm giving is out of range. Anyone know what I'm doing (or not doing) wrong here???
 
I didn't fully check our your code, but I think that if you set the maximum value of int z at tableTeamMembersTasks.Rows.Count - 1
it might clear up the error. I can't remember the details, but I think you array as a base of 0 while your tableTeamMembersTasks table has a base of 1.

Good luck
Tomt
 
No that isn't the problem. I tried your idea just to be certain, but the values are correct as they stand. Is the scope of the variable &quot;numberOfWorkers&quot; changing or something? This is just very strange... strange indeed..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top