Solved

Getting field index from field name using sqlDataReader

Posted on 2004-08-04
2
623 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 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