473,507 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Looping through an array

I have been able to run a query and get the results in an Arraylist. Query returns 2 results
alist[0] and alist[1]
//OUTPUT
DBID,VERSION,DB_NAME,INSTANCE_NAME,HOST_NAME
alist[0] == 806497854,10.2.0.5.0,ALPHA,ALPHA,ALPHA-SERVE alist[1] == 3895980978,10.2.0.1.0,BETA,BETA,BETA-SERVER
// END OF OUTPUT

as you can see from the output, within the alist[0] I have 5 ItemArray objects
I'm trying to get a checkbox populated with list of items from arraylist. I'm getting "Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index" error. here is the code
Expand|Select|Wrap|Line Numbers
  1. alist = new ArrayList();
  2.             alist = (ArrayList)ProgramLogic.runsqlAL(sqltext, Form1.OraConn);
  3.             // alist has 2 items 0 and 1
  4.             // alist itemArray has 5 objects in each itemlist
  5.             for ( int i = 0; i <= alist.Count;i++)
  6.             {
  7.                 for (int j = 0; j <= (((DataRow)alist[i]).ItemArray.Count()); j++)
  8.                 {
  9.                     MessageBox.Show("i is " + i.ToString() + "and j is " + j.ToString());
  10.                     //avail_dbid_CB.Items.Add(((DataRow)alist[i]).ItemArray[j].ToString());
  11.                 }
  12.             }
  13.  
any help would be greatly appreciated
Oct 5 '10 #1
1 1357
Christian Binder
218 Recognized Expert New Member
You have to use i < ...Count instead of i <= ...Count. The same for j.

It's because when Count is 2, you would access array[0], array[1] and array[2] but array[2] doesn't exist.
Oct 6 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
3497
by: Laphan | last post by:
Hi All I'm using .getRows() with a local var array instead of doing a recursive loop so that I'm being a good ASP newvbie and closing my object i/o's (the recordset in this case) as quick as...
26
9566
by: JGH | last post by:
How can I check if a key is defined in an associative array? var users = new array(); users = "Joe Blow"; users = "John Doe"; users = "Jane Doe"; function isUser (userID) { if (?????)
35
6591
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
11
2039
by: cdg | last post by:
Could anyone tell me how to write a loop for an array, that would have to check each iteration for duplications of previous entered values. So, the exact number of loops is not known, but the total...
12
4032
by: neeraj | last post by:
Hi Can any body give me the syntax for summing the elements of the an array , without looping thanks
9
1826
by: IamIan | last post by:
I'm using an array to store map features (name, lat, lon, caption, etc), from which the user can then select an individual feature. The problem is that when thousands of features are stored in the...
1
1837
by: assgar | last post by:
Hello I have changed the process code abit so it receives the data from the form and ensures the data in array format. This has eliminated my previous error. The problem I am experiencing...
4
3167
by: Bob | last post by:
Is there a faster way to add the array elements to a list then looping through the elements like: double toadd; list<doublelistwant; for (int i=0;i<toadd.Length;i++){ listwant.Add(toadd);
8
1867
by: isaac2004 | last post by:
hello, i posted with a topic like this but got no real feedback(prob cuz of lapse in my explanation) so i am trying it again. i am trying to set up a function that brings in a txt file and adds the...
1
5110
by: nlal | last post by:
Hi I have a small program that takes a 10bit key, compresses it into 8bit key and does a left shift 8times, generating a key each time. I am using a one dimensional array to store the key value of...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.