When retrieving values from a DataRow is it better to use the column name or column index?
The column name is more readable and easier to maintain:
int price = (int)dr["Price"];
While column index is just faster (I think):
int price = (int)dr[3];
Would using column names break if you decide to obfuscate the database?
I generally prefer readability and understanding over speed. Go with the name. You could (should) use string constants that can be updated in one place if you decide to change database column names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With