emub
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If DataReader.Getname(a) = Name Then
do whatever
End If
End While
Regards,
Aeros