954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

DataTable to ArrayList using AddRange, No Zeroth Element

I am trying to populate an ArrayList using the elements from a DataTable. I know I could do this using Loop, but I am trying to figure out how to using AddRange.

Here's my code:

SomeArrayList.AddRange(SomeDataTable.Rows.Item(0).ItemArray)


The problem is that I can pass the collection except for the Zeroth element.

This is the collection I am trying to pass to the ArrayList:
1. Dog
2. Cat
3. Bird

This is what I got
1. Cat
2. Bird

yorro
Junior Poster
121 posts since Aug 2009
Reputation Points: 8
Solved Threads: 7
 

Hi,

You can use the AddRange method to do so.
For more explanation, look here.

Luc001
Posting Whiz
376 posts since Mar 2010
Reputation Points: 85
Solved Threads: 98
 

Hi,

You can use the AddRange method to do so. For more explanation, look here.

Hi,

I've already used the AddRange, and it works(barely). My Question still stands: Why does the Index 0 of the collectionSomeDataTable.Rows.Item(0).ItemArray is not present in the SomeArrayList.

yorro
Junior Poster
121 posts since Aug 2009
Reputation Points: 8
Solved Threads: 7
 

Hi,

I think you'll need to use the ArrayList.IndexOf method for that.
Look, here.

Luc001
Posting Whiz
376 posts since Mar 2010
Reputation Points: 85
Solved Threads: 98
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: