Question: Getting data from a field in a DataReader

  • Thread starter Thread starter VB Programmer
  • Start date Start date
V

VB Programmer

I have a DataReader. How can I get the value of a column in the current
"row" if I have only the NAME of the column, not it's ordinal value?

If I knew the ordinal value of the column I could just go:
MyDataReader.GetValue(2)

But, this is invalid:
MyDataReader.GetValue("CustomerName")

Thanks.
 
Use the indexer. MyDataReader("MyColumn") (in vb) or
MyDataReader["MyColumn"] (in C#). These calls will return an object, and
you may have to cast it to the appropriate data type.
 
Back
Top