|
-
January 30th, 2008, 04:59 PM
#1
getField() with ordinal fails : VC++ (2008 express) and SQL Server (2005 express)
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?
Last edited by valley; January 30th, 2008 at 05:07 PM.
-
January 30th, 2008, 05:53 PM
#2
Re: getField() with ordinal fails : VC++ (2008 express) and SQL Server (2005 express)
And almost immediately after I posted this, I stumbled on the answer.
So for anyone else that may run into this issue, you need to cast your ordinal index as a long, so:
recordset->GetFields()->GetItem(0)
wont work, but:
recordset->GetFields()->GetItem(long(0))
will.
Grrr...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|