Results 1 to 8 of 8

Thread: ArrayList vs Datatable

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    159

    ArrayList vs Datatable

    I am kind of wondering which one is better?
    I trying to pass data that I got in one dataTable (already) to store it in my database. But Would it be better to pass it to my Business Clasess as a datatable or a ArrayList and why ?
    Maybe It sounds silly , and just should pass it as it is (Datatable), But I want to know which is better?

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: ArrayList vs Datatable

    If your going to be reading/writing from a database, stick with the datatable. ADO.NET deals with the datatable/dataset objects natively.

  3. #3
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: ArrayList vs Datatable

    ArrayList is slow because everything within it has to be cast as another object before use. A DataTable is slow due to all of its functionality but for what you're doing, I'd imagine a DataTable would be quicker and/or better.

    If it's possible I would opt for a custom class that contains all of the data and using something like a List<MyClass> to hold it all and skip the DataSet / DataTable entirely. Of course, if you're going to eventually go into a DataGrid, DataSet or DataTable then it would be a bit pointless to use a class like I suggest.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: ArrayList vs Datatable

    You've already got your data in a DataTable. You want to build business objects around this data. What possible advantage can you imagine by copying the data to an ArrayList first? If you think that it might be a good idea then you must have some idea of why it might. What do you think?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: ArrayList vs Datatable

    Wouldn't it be best to first consider how many columns of data will be stored?

    I find that if you need to add/remove data at runtime a List will be of benefit, and if you need to store a specific key with something else then a Dictionary or HashTable would be most appropriate. If you had to use a List then i really wouldn't go with LinkedList<T> as List<T> is a little bit better performance wise but again its up to you

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2005
    Posts
    159

    Resolved Re: ArrayList vs Datatable

    . Im using a List<T> because I am going to change(filter) data and not store all the information from the data table.
    Thx 4 the replies

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: ArrayList vs Datatable

    Are you aware that the DataTable class already supports filtering via its DefaultView.RowFilter property or its Select method?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: ArrayList vs Datatable

    While a List<T> may be technically quicker than a DataTable or DataSet due to less overhead, you should factor in the DataTable and DataSet features before making a decision. As jmcilhinney said, the DataTable can do filtering as well.

    If your ultimate goal is to display data in a tabular fashion, then stick with the DataTable.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

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