Question: Getting data from a field in a DataReader

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.
 
M

Marina

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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top