Solved

Getting field index from field name using sqlDataReader

Posted on 2004-08-04
2
614 Views
Last Modified: 2006-11-17
Hi,

Im trying to find a quick way of getting the field number from just having the field name using sqlClient.sqlDataReader.

I could do a loop though each field untill I reach the correct field then pass back the index number, but I was wonder if there was an easier way?

[example - my current solution]
Function ReturnFieldIndex(byval Name as String, byval DataReader as sqlClient.sqlDataReader) as Integer
  For a = 0 To DataReader.FieldCount - 1
     If DataReader.GetName(a) = Name Then
         Return a
     End If
  Next a
End Function
0
Comment
Question by:emub
2 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11715157
While datareader.read
If DataReader.Getname(a) = Name Then
do whatever
End If
End While

Regards,

Aeros
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 250 total points
ID: 11715388
dim x as integer =   yourdatareader.GetOrdinal("Yourcolumnname")
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now