Accessing DataTable Columns

  • Thread starter Thread starter Stephen Wood
  • Start date Start date
S

Stephen Wood

Simple question: when accessing column values, is numerical indexing faster
than referencing by column name? I know that in the case of the DataReader,
the answer is yes; was just wondering if the same applies to a DataTable.

Regards,

Stephen
 
Yes, much faster. Since there isnt' a getordinal method with DataTables,
Bill Vaughn came up with one of the slickest ideas I've seen in a while.
Create an enum wherein the enum index corresponds to the DataTable Column's
index, and the Name corresponds to the enumerated name. Then use the Enum
for referencing. This gives you the advanced speed, it works faster than
GetOrdinal b/c you don't have to read in any schema information and you get
the clarity of the Name based lookups.

When it's said and done, the same issue applies, at each pass, a name based
lookup needs to be performed and the name resolved, so using an index is
going to be faster across the board.

HTH,

Bill
 
Back
Top