Question: Getting data from a field in a DataReader

Discussion in 'ASP .Net' started by VB Programmer, Aug 13, 2003.

  1. 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.
    VB Programmer, Aug 13, 2003
    #1
    1. Advertising

  2. VB Programmer

    Marina Guest

    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.

    "VB Programmer" <> wrote in message
    news:%...
    > 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.
    >
    >
    Marina, Aug 13, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin
    Replies:
    2
    Views:
    9,158
    Kevin
    Dec 18, 2003
  2. Martin Raychev
    Replies:
    2
    Views:
    3,342
    bruce barker
    Apr 22, 2004
  3. Shapper
    Replies:
    1
    Views:
    515
    Lucas Tam
    Apr 22, 2005
  4. Sound
    Replies:
    2
    Views:
    428
    Randy Webb
    Sep 28, 2006
  5. jr
    Replies:
    3
    Views:
    405
Loading...

Share This Page