Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it better to use the column name or column index on .Net DataSets?

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?

like image 683
tpower Avatar asked Jan 23 '09 15:01

tpower


1 Answers

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.

like image 68
tvanfosson Avatar answered Nov 02 '22 03:11

tvanfosson