How to convert datatable into an arraylist

S

Steve

I have a very simple datatable of 1 column which I retrieve from a
database, call it 'data'.

Dim data As Data.DataTable
data = myobject.mymethod(parameter)

I want to now turn this 'data' into an arraylist and I don't know how.
Can anyone help?



And finally I want to convert the arraylist to a 'string array' which I
think can be done by:

Dim ListArray As String() = List.ToArray(GetType(String))

Please help in vb.net code. I am using asp.net 2.0 if that makes any
difference.
 
K

Karl Seguin

I doubt you'll find a way to implicitely conver it. You'll need to loop
through and add

dim Listas new ArrayList(data.Rows.Count)
for each row as DataRow in data.Rows
List.Add(row(0))
next

ur convert to string is fine, you'll need to
ctype(List.ToArray(GetType(String), string()) (cast to string array) more
than likely

Karl
 
S

Steve

Thank you Karl. I think this should do it. As you say, it's a pitty
there isn't a simple built in method to turn a datatable into an array.
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top