|
-
Jan 23rd, 2008, 02:18 PM
#1
Thread Starter
Addicted Member
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?
-
Jan 23rd, 2008, 02:44 PM
#2
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.
-
Jan 23rd, 2008, 04:10 PM
#3
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.
-
Jan 23rd, 2008, 08:00 PM
#4
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?
-
Jan 23rd, 2008, 08:34 PM
#5
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
-
Jan 24th, 2008, 01:57 PM
#6
Thread Starter
Addicted Member
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
-
Jan 24th, 2008, 05:32 PM
#7
Re: ArrayList vs Datatable
Are you aware that the DataTable class already supports filtering via its DefaultView.RowFilter property or its Select method?
-
Jan 25th, 2008, 01:24 PM
#8
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.
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
|