valley
January 30th, 2008, 03:59 PM
Hi,
I'm hoping this hasn't been answered many times before. I couldn't find anything in the search.
I'm using MSVC++ 2008 Express, alongside MS SQL Server 2005 Express, and trying to connect via ADO.
My problem basically is that I'm trying to iterate through a list of fields in a recordset by ordinal index rather than by name.
The recordset was created by an SQL query such as SELECT * FROM mytable, or SELECT field1, field2 FROM mytable.
In both cases, I can see the that the recordset contains records (the correct amount for the select) and those records contain fields (again the correct amount). Further I can access the fields by using:
recordset->GetFields()->GetItem("field1")
but if I try to do:
recordset->GetFields()->GetItem(0)
I get an exception to the effect of the field requested does not exist.
I can't see why this isn't working. The docs on MSDN suggest that iterating by ordinal is acceptable, and I've seen plenty of VB code that does it. I've not seen any C++ code examples that do though, so I might be missing a step.
Can anyone offer any help?
I'm hoping this hasn't been answered many times before. I couldn't find anything in the search.
I'm using MSVC++ 2008 Express, alongside MS SQL Server 2005 Express, and trying to connect via ADO.
My problem basically is that I'm trying to iterate through a list of fields in a recordset by ordinal index rather than by name.
The recordset was created by an SQL query such as SELECT * FROM mytable, or SELECT field1, field2 FROM mytable.
In both cases, I can see the that the recordset contains records (the correct amount for the select) and those records contain fields (again the correct amount). Further I can access the fields by using:
recordset->GetFields()->GetItem("field1")
but if I try to do:
recordset->GetFields()->GetItem(0)
I get an exception to the effect of the field requested does not exist.
I can't see why this isn't working. The docs on MSDN suggest that iterating by ordinal is acceptable, and I've seen plenty of VB code that does it. I've not seen any C++ code examples that do though, so I might be missing a step.
Can anyone offer any help?