473,809 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.mymeth od(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(Ge tType(String))

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

Nov 19 '05 #1
2 31442
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.ToAr ray(GetType(Str ing), string()) (cast to string array) more
than likely

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/

"Steve" <ba****@iranman ia.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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.mymeth od(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(Ge tType(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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
13382
by: mimi | last post by:
I would like to convert an arraylist to dataset or datatable so that I can filter or make a select distinct from it. How to do it? Can someone show me the syntax? Thanks
1
1865
by: George | last post by:
I am wondering what is the cost of using DataTable. Lets say i have 1000 Employee records. The object oriented purist will require the Data Layer to return an ArrayList with 1000 Employee objects. But very often we (at least i) returning DataTable to populate the grid. But now i am wondering: Am i gaining anything? The DataTable has to create object DataRow for each row. Versus i am creating Employee object for each row. So unless...
6
5390
by: gane kol | last post by:
Hi, I have a code that creates a datatable from an arraylist, but i am getting an error in casting in for (int intRow = 0; intRow < alLCPlist.Count; intRow++) { DataRow drow = dtLCPack.NewRow(); int intColCount = dtLCPack.Columns.Count; ArrayList arrlRow = (ArrayList)alLCPlist; <== Specified cast
1
4558
by: Joseph | last post by:
Hi all, I know that you can convert a Dataset into an Arraylist, I was wondering if it is possible to do the opposite - Convert an Arraylist to a Dataset? If so, how do you do this? An example of this would be much appreciated. Thanks
3
5899
by: David | last post by:
Hi all, I am following this code... http://www.devarticles.com/c/a/C-Sharp/Interface-IEnumerable-and-IEnumerator-in-C-sharp/2/ I have come to the part with public Customers(). I am assuming this is a constructor (as it is the same name as the class). In here, it says Get all customer ids from the database and put into an arraylist. However, the code is for enumeration. To me, all data from a
15
60637
by: =?Utf-8?B?cm9nZXJfMjc=?= | last post by:
hey, I have a datatable here, but I need to make it into a string array. how do I do that?
4
12601
by: =?Utf-8?B?YmFzdWxhc3o=?= | last post by:
Hi; I want to store a datatable (or an arraylist) as a session variable but when I try; Session = al_RecNo; I get an error that; "Cannot implicitly convert type 'System.Collections.ArrayList' to 'string'"
4
3221
by: StinkyDuck | last post by:
I'm trying to determine which type of collection to use, DataTable or ArrayList. I understand that an ArrayList can be linked to databound objects if it contains the IList interface. Is there a recommendation to use one over the other. If you are not going to bind the collection to any objects should an ArrayList be used? Is there a benefit on size? If I have a 200,000 rows of data, should a DataTable be used in this case? Any...
2
1917
by: Mr. Arnold | last post by:
I am working a C# project that uses what's in the subject. I kind of have the basics down on reading the table data. I don't use the above methods of data access or persistence, but I am stuck with using this them in this project. I have selected rows based on selection criteria and the rows/records are held in an ArrayList, so I can work with those rows/records, as the user makes a selection to work with the data on the screen from a...
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10640
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
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 we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.