tags:

views:

380

answers:

3

What is the best way of handling trying to get data from a DataReader that has more than one column with the same name?

Because of the amount of work involved and because we don't want to lose support from a vendor by changing the stored procedures we are using to retrieve the data, I am trying to find another way to get access to a column that shows up more than once in a datareader without having to rewrite the stored procedures.

Any Ideas?

EDIT: Ok, the function that actually populates from a datareader is used in multiple places so there is a possibility that the function can be called by different stored procedures. What I did was to do a GetName using the index to check if it is the correct column, and if it is, then pull its value.

Thanks again.

+1  A: 

Can't you use column ordinals? 0 for the 1st, 1 for the 2nd, and so on?

Tom Ritter
+3  A: 

If you know the index of the column, then access it by the index.

Matthew
+1  A: 

You will have to reference the column by index no; i.e. reader[5].ToString(); to read the data in column 5.

related questions