Simple question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary

    #1

    Simple question

    Hi,

    I have a question is regarding OLEDbDataReader

    Is there a way to access Data filled to an OLEDBDataReader using field name
    instead of field position.

    If not possible using OLEDbDataReader , is there any alternative to achieve
    this?

    TIA,

    Gary


  • Dominique Kuster

    #2
    Re: Simple question

    "Gary" <msnews@microso ft.com> wrote in message
    news:%23UforjgZ DHA.2632@TK2MSF TNGP09.phx.gbl. ..[color=blue]
    > I have a question is regarding OLEDbDataReader
    > Is there a way to access Data filled to an OLEDBDataReader using field[/color]
    name[color=blue]
    > instead of field position.[/color]
    Declare variables and store the position of selected fields before you start
    the read loop :
    VB.NET:
    Dim iFirstnamePosit ion As Integer = myReader.GetOrd inal("first_nam e")
    Dim iLastnamePositi on As Integer = myReader.GetOrd inal("last_name ")
    Do While myReader.Read()
    Console.WriteLi ne("Full name: {0} {1}",
    myReader.GetStr ing(iFirstNameP osition),
    myReader.GetStr ing(iLastNamePo sition))
    Loop

    C#:
    int iFirstNamePosit ion = myReader.GetOrd inal("first_nam e");
    int iLastNamePositi on = myReader.GetOrd inal("last_name ");
    while (myReaderRead() ) {
    Console.WriteLi ne("Full name: {0} {1}",
    myReader.GetStr ing(iFirstNameP osition),
    myReader.GetStr ing(iLastNamePo sition));
    }

    The xxxDataReader is supposed to be very performant, you would have a
    performance decrease if you lookup a field name every time you fetch a new
    row. Working with column ordinals is the fastest method.

    Comment

    Working...