Link to home
Start Free TrialLog in
Avatar of emub
emubFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Getting field index from field name using sqlDataReader

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
Avatar of AerosSaga
AerosSaga

While datareader.read
If DataReader.Getname(a) = Name Then
do whatever
End If
End While

Regards,

Aeros
ASKER CERTIFIED SOLUTION
Avatar of RonaldBiemans
RonaldBiemans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial