How can I take an ArrayList and turn it into a DataTable?
Thanks
Printable View
How can I take an ArrayList and turn it into a DataTable?
Thanks
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.
thanks Mendhak, do you have a code snippet on how to do that?
Thanks
Real simple example:
VB Code:
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.
cool
Good, now add [Resolved] to this thread and head over to Chit-Chat. :afrog: http://www.vbforums.com/attachment.p...postid=1599755
Here's an answer written in C#...
http://tomgilkison.blogspot.com/2008...datatable.html
Hi vanny,
This thread is 3 years old. Were you looking to promote your website (assuming that's your blog)?
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.
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.
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.