Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting field index from field name using sqlDataReader

Posted on 2004-08-04
2
Medium Priority
?
633 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 1000 total points
ID: 11715388
dim x as integer =   yourdatareader.GetOrdinal("Yourcolumnname")
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

721 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