Accessing DataTable Columns

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
 
W

William Ryan eMVP

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
 
G

Greg

+1 for Bill's idea. This is exactly what we do. Who thought of it first,
Bill or us? ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top