467,161 Members | 889 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 developers. It's quick & easy.

How to convert datatable into an arraylist

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.

Nov 19 '05 #1
  • viewed: 31163
Share:
2 Replies
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
--
MY ASP.Net tutorials
http://www.openmymind.net/

"Steve" <ba****@iranmania.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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.

Nov 19 '05 #2
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.

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by George | last post: by
6 posts views Thread by gane kol | last post: by
1 post views Thread by Joseph | last post: by
3 posts views Thread by David | last post: by
15 posts views Thread by =?Utf-8?B?cm9nZXJfMjc=?= | last post: by
4 posts views Thread by =?Utf-8?B?YmFzdWxhc3o=?= | last post: by
4 posts views Thread by StinkyDuck | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.