DataReader - GetOrdinal - Performance Improvement

Whenever you access the values from DataReader, dont access it using the column names, instead go for Index based lookup. Surely it will improve the performance of the code. Eventhough it increased the code maintainablity, performance wise you will get a good response.

dr["ColumnName"] - Not a good way - Performance lacks here.

Instead, there is method called GetOrdinal for a datareader, through that you can get the index of the particular column, assign it to an integer variable and access the values through that.

Sample code is

int tempIndex = dr.GetOrdinal("name");

dr[tempIndex] -> Good Way - Performance will be improved here.
Ebook Download
View all
Learn
View all