|
-
Oct 4th, 2005, 10:20 AM
#1
Thread Starter
PowerPoster
Convert ArrayList into DataTable
How can I take an ArrayList and turn it into a DataTable?
Thanks
-
Oct 4th, 2005, 05:42 PM
#2
Re: Convert ArrayList into DataTable
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.
-
Oct 5th, 2005, 06:45 AM
#3
Thread Starter
PowerPoster
Re: Convert ArrayList into DataTable
thanks Mendhak, do you have a code snippet on how to do that?
Thanks
-
Oct 5th, 2005, 10:30 AM
#4
Re: Convert ArrayList into DataTable
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.
-
Oct 5th, 2005, 10:35 AM
#5
Thread Starter
PowerPoster
Re: Convert ArrayList into DataTable
-
Oct 5th, 2005, 10:36 AM
#6
Re: Convert ArrayList into DataTable
Good, now add [Resolved] to this thread and head over to Chit-Chat.
-
May 15th, 2008, 11:12 AM
#7
New Member
Re: Convert ArrayList into DataTable
-
May 16th, 2008, 01:38 PM
#8
Re: Convert ArrayList into DataTable
Hi vanny,
This thread is 3 years old. Were you looking to promote your website (assuming that's your blog)?
-
Jun 9th, 2008, 01:04 PM
#9
New Member
Re: Convert ArrayList into DataTable
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.
Last edited by mendhak; Jun 9th, 2008 at 01:14 PM.
-
Jun 9th, 2008, 01:14 PM
#10
Re: Convert ArrayList into DataTable
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.
-
Jun 9th, 2008, 01:52 PM
#11
New Member
Re: Convert ArrayList into DataTable
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|