I am currently working on a web application. I was just wondering which has a better performance when used as a DataSource for say a DataGridView or a DropDownList control.
I believe that DataTable is harder to create unless you get it from a DataReader but if you have a ORM layer that abstract the use of DataAccess classes like DataReader and the ORM library usually returns an array list. With this case creating a DataTable is very tedious. I am wondering also how the DataSource handles the selecting of DataTextField and DataValueField in an ArrayList… Is it via reflection? If so using Reflection would be a performance decrease? But for DataTable, it has a complete meta-data so I think it would be faster.
What do you think?
A List (which I hope you’d use instead of an ArrayList) is a lighter-weight structure than a DataTable. If your ORM returns an ArrayList, then it doesn’t make much sense to convert it to a DataTable and then use that DataTable as the DataSource for a control. This is extra work; in general, I would use a DataTable (filled up by a DataAdapter) or I would use an ORM, but not both together. Although the DataTable is “heavier” than an ArrayList, I doubt the difference is all that significant.
I do not think the DataSource of a grid or other control uses Reflection for either a DataTable or an ArrayList, and if it does, Reflection is probably not used on a row-by-row basis.