By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

Simple question

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Gary" <ms****@microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP09.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 iFirstnamePosition As Integer = myReader.GetOrdinal("first_name")
Dim iLastnamePosition As Integer = myReader.GetOrdinal("last_name")
Do While myReader.Read()
Console.WriteLine("Full name: {0} {1}",
myReader.GetString(iFirstNamePosition),
myReader.GetString(iLastNamePosition))
Loop

C#:
int iFirstNamePosition = myReader.GetOrdinal("first_name");
int iLastNamePosition = myReader.GetOrdinal("last_name");
while (myReaderRead()) {
Console.WriteLine("Full name: {0} {1}",
myReader.GetString(iFirstNamePosition),
myReader.GetString(iLastNamePosition));
}

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.

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.