"Gary" <ms****@microso ft.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
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.
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.