Is there a way to refernece these fields by name? In VB 6 i could
access the field value with something similar to:
value=rs("Fieldname")
(1) value=rs("Fieldname") is actually value=rs.fields("Fieldname") Note
that you MUST specify all properties in .Net. The fields property is the
DEFAULT property in VB6 ADO. We all got lazy being able to leave this
out.
(2) The ADO recordset object, when persented with a string argument,
traverses itself looking for a match on field name and then using the
index that it located to fetch the value. If you know the index it is
much faster to just go get it. I regularly have tables with well over a
hundred fields. If I have a few thousand rows returned, which is common,
that is a few hundred thousand extra things that needed to be done for me
do get my data.
(3) Don't use SELECT *. I had several customers that applied an update
to their ERP package that rearranged the schema putting all the fields in
alphabetic order. Lots of custom code that assumed the fields to be in a
certain order broke because of SELECT *.
|==========|
| Solution |
|==========|
You can search for the field name yourself:
Dim iIndex as Integer = -1
Dim i as Integer
For i = 0 to myReader.FieldCount -1
If Ucase(sSearchArg) = Ucase(myReader.GetName(i)) Then
iIndex = i
Exit For
End If
Next i
This is what ADO was doing for you in the background anyway.