ArrayList

  • Thread starter Thread starter zion
  • Start date Start date
Z

zion

Hello,

I build arraylist from SqlDataReader with 3 fields.
How Can I get for example the record number 100 and the second field?

Thanks
 
I build arraylist from SqlDataReader with 3 fields.

And what is each element of the ArrayList? A DataRow? An array?
How Can I get for example the record number 100 and the second field?

Well, you can use myArrayList[99] to get the 100th element you added.
From there, getting the second field will depend on how you've stored
the data.

Jon
 
Hello,

This is my code:

ArrayList MyArray= new ArrayList();
while (dbReader.Read())

{

object[] values = new object[dbReader.FieldCount];

dbReader.GetValues(values);

MyArray.Add(values);

}

Thanks
 
zion said:
Hello,

This is my code:

ArrayList MyArray= new ArrayList();
while (dbReader.Read())

{

object[] values = new object[dbReader.FieldCount];

dbReader.GetValues(values);

MyArray.Add(values);

}

Then the secind field in record number 100 would be:

((object[])MyArray[99])[1]

I suppose, the your record numberin begins with 1.
If it begins with 0, then record number and the element index in MyArray are
in sync so:

((object[])MyArray[100])[1]


If you use C#2.0/Visual Studie 2005 (or higher) you should prefer List<> for
ArrayList:

List<object[]> = new List<object[]>();
while (dbReader.Read())
{
object[] values = new object[dbReader.FieldCount];
dbReader.GetValues(values);
MyArray.Add(values);
}

.....
MyArray[100][0] //No espl. cast needed here, because Element-Typ of MyArray
is known as object[].

HTH
Christof
}
 
Thanks

(-:

Christof Nordiek said:
zion said:
Hello,

This is my code:

ArrayList MyArray= new ArrayList();
while (dbReader.Read())

{

object[] values = new object[dbReader.FieldCount];

dbReader.GetValues(values);

MyArray.Add(values);

}

Then the secind field in record number 100 would be:

((object[])MyArray[99])[1]

I suppose, the your record numberin begins with 1.
If it begins with 0, then record number and the element index in MyArray
are in sync so:

((object[])MyArray[100])[1]


If you use C#2.0/Visual Studie 2005 (or higher) you should prefer List<>
for ArrayList:

List<object[]> = new List<object[]>();
while (dbReader.Read())
{
object[] values = new object[dbReader.FieldCount];
dbReader.GetValues(values);
MyArray.Add(values);
}

....
MyArray[100][0] //No espl. cast needed here, because Element-Typ of
MyArray is known as object[].

HTH
Christof
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top