When returning data from a DataReader
I would typically use the ordinal reference on the DataReader
to grab the relevant column:
if
Indexing the data reader by name is slightly more expensive. There are two main reasons for this.
However, in most cases the performance penalty incurred by looking up a field by name is dwarfed by the amount of time it takes for the database to execute the command. Do not let the performance penalty dictate your choice between name and numeric indexing.
Despite the slight performance penalty I normally choose name indexing for two reasons.
If you feel like the performance penalty of name indexing is becoming problematic (maybe the command executes quickly, but returns a lot of rows) then lookup the numeric index once by name, save it away, and use it for the remaining rows.