Results 1 to 11 of 11

Thread: Convert ArrayList into DataTable

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Convert ArrayList into DataTable

    How can I take an ArrayList and turn it into a DataTable?
    Thanks

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: Convert ArrayList into DataTable

    thanks Mendhak, do you have a code snippet on how to do that?
    Thanks

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Convert ArrayList into DataTable

    Real simple example:

    VB Code:
    1. Dim al As New ArrayList
    2.  
    3.         al.Add(18)
    4.         al.Add(19)
    5.         al.Add(238)
    6.         al.Add(338)
    7.         al.Add(998)
    8.         al.Add(13830)
    9.  
    10.  
    11.         Dim dt As New DataTable
    12.         dt.Columns.Add("JustANumber")
    13.  
    14.         For i As Integer = 0 To al.Count - 1
    15.             Dim dr As DataRow
    16.             dr = dt.NewRow()
    17.             dr.Item(0) = al.Item(i)
    18.             dt.Rows.Add(dr)
    19.  
    20.         Next

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

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: Convert ArrayList into DataTable

    cool

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Convert ArrayList into DataTable

    Good, now add [Resolved] to this thread and head over to Chit-Chat.

  7. #7
    New Member
    Join Date
    May 2008
    Posts
    3

    Re: Convert ArrayList into DataTable

    Here's an answer written in C#...

    http://tomgilkison.blogspot.com/2008...datatable.html

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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)?

  9. #9
    New Member
    Join Date
    May 2008
    Posts
    3

    Wink 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.

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  11. #11
    New Member
    Join Date
    May 2008
    Posts
    3

    Thumbs up 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
  •  



Click Here to Expand Forum to Full Width