I created a simple test scenario that compared the performance of a
DataReader vs. a strongly typed DataTable. It seems that it is indeed
quicker to traverse the result set when using the DataReader, but once you
try to read the actual columns of the data, you lose all the benefits.
When you have to make double method calls like:
string strval = dr.GetString(dr.GetOrdinal("somecolumn"));
just to read a single column value, it stands to reason that it's less
efficient than:
string strval = dataTable[i].somecolumn;
In my tests, I found that if you have to read more than two columns of the
row, the speed was about the same as using the strongly typed DataTable.
Beyond that, the DataTable was more efficient.
I also ran a similar test by binding the DataReader to an ASP.NET GridView
server control, and it was no faster at rendering than when using a
DataTable.
I understand that the DataReader takes less overhead and theoretically
should be faster than a strongly typed DataTable, but I don't see the
benefit in a real-world situation. When you're actually doing something with
that data.
So am I missing something?
|