PDA

Click to See Complete Forum and Search --> : Convert ArrayList into DataTable


jesus4u
Oct 4th, 2005, 10:20 AM
How can I take an ArrayList and turn it into a DataTable?
Thanks

mendhak
Oct 4th, 2005, 05:42 PM
If you're looking to bind a control to the datatable, you can simply bind to the ArrayList. Is that what you want? Else you can simply loop through all the items in the arraylist, creating a datarow in each loop, and adding the datrow to your datatable.

jesus4u
Oct 5th, 2005, 06:45 AM
thanks Mendhak, do you have a code snippet on how to do that?
Thanks

mendhak
Oct 5th, 2005, 10:30 AM
Real simple example:


Dim al As New ArrayList

al.Add(18)
al.Add(19)
al.Add(238)
al.Add(338)
al.Add(998)
al.Add(13830)


Dim dt As New DataTable
dt.Columns.Add("JustANumber")

For i As Integer = 0 To al.Count - 1
Dim dr As DataRow
dr = dt.NewRow()
dr.Item(0) = al.Item(i)
dt.Rows.Add(dr)

Next



If you have objects in your arraylist instead of primtive types, you can expand on it of course.

jesus4u
Oct 5th, 2005, 10:35 AM
cool

mendhak
Oct 5th, 2005, 10:36 AM
Good, now add [Resolved] to this thread and head over to Chit-Chat. :afrog: http://www.vbforums.com/attachment.php?s=&postid=1599755

vannyd
May 15th, 2008, 11:12 AM
Here's an answer written in C#...

http://tomgilkison.blogspot.com/2008/05/convert-arraylist-to-datatable.html

mendhak
May 16th, 2008, 01:38 PM
Hi vanny,

This thread is 3 years old. Were you looking to promote your website (assuming that's your blog)?

vannyd
Jun 9th, 2008, 01:04 PM
I'm looking to promote useful information wherever possible.

1. Google for a solution to my problem
2. If I cannot find the answer on Google, work on the issue until it is resolved
3. Post the answer on my blog
4. Go back to the forums and blogs to drop links so that others looking for the answer can find it and resolve their issues without much effort.

If you are asking me about personal motivation, Google sent me my first $100 AdSense check in January for 3 years. I would encourage you to help others as well, putting up good information.

Here...let me promote my latest work offered up for free to those in need of this solution:

Install a Windows Service which Pings a Web Service with a Tock() method every X minutes to run an ASP.NET Scheduled Process:

[REMOVED]

Thanks for helping out the community by maintaining a 3 year old thread.

mendhak
Jun 9th, 2008, 01:14 PM
You can submit your code snippets to the codebank if you'd like. However, considering that the link you've posted contains a link to a website that requires registration, that really isn't anything - so I've removed your link. The point of helping people on forums is to share code, not get them to register to look at it. You are always welcome to create a new codebank thread if you want to share it here.

vannyd
Jun 9th, 2008, 01:52 PM
Ah...my bad. Thanks for forcing me to figure out why I couldn't open up the code without requiring registration. There was a setting in the Admin area of Assembla which allowed me to give view access to the world. Fixed. No need to post the link since it is off topic.

Keep helping people solve problems faster!

Oh yea...forgot to mention. The reason that I post links to forums and blogs after providing a solution is to boost the actual solution to a higher level in Google (page rank). It would be horrible if the solution were out on the Internet, but nobody could find it because the "mega search engine" didn't rank it near the top!

I would encourage anyone to post 'on topic' links back to their blog by making comments on my blog. You are also more than welcome to copy my code and drop it in your forum.