Solved

Getting field index from field name using sqlDataReader

Posted on 2004-08-04
2
618 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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 …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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