trustworthy
asked on
CRecordset "Invalid Descriptor Index "
Hi all,
Here's my code:
SQL = SELECT ID,X,Y,A,TYPEID, vid FROM (SELECT ID,A,X,Y,TYPEID, (SELECT TOP 1 ID FROM DETAILS d WHERE pos.ID = d.ID) AS vid, row_number() over (partition by ID order by CREATEDTIME desc) as rn FROM POST pos) AS ss WHERE rn = 1;
CDatabase* pDatabase = new CDatabase();
pDatabase->Open(_T(""),FAL SE,FALSE,L PCTSTR(sDs n));
CRecordset rs( pDatabase );
rs.m_bUseODBCCursorLib = TRUE;
BOOL iReturn = rs.Open(SQL ,CRecordset::forwardOnly,C Recordset: :readOnly) ;
while(!rs.IsEOF() )
{
CDBVariant v;
memset(&v,0,sizeof(CDBVari ant));
rs.GetFieldValue((short)0, v, SQL_C_SLONG);
//always the ERROR here
}
I searched high and low, but so far unable to solve this.
Maybe there's something wrong with my SQL? But
this only happens on SQLServer (I tried different databases on different versions).
Works fine in DB2.
Please help.
Here's my code:
SQL = SELECT ID,X,Y,A,TYPEID, vid FROM (SELECT ID,A,X,Y,TYPEID, (SELECT TOP 1 ID FROM DETAILS d WHERE pos.ID = d.ID) AS vid, row_number() over (partition by ID order by CREATEDTIME desc) as rn FROM POST pos) AS ss WHERE rn = 1;
CDatabase* pDatabase = new CDatabase();
pDatabase->Open(_T(""),FAL
CRecordset rs( pDatabase );
rs.m_bUseODBCCursorLib = TRUE;
BOOL iReturn = rs.Open(SQL ,CRecordset::forwardOnly,C
while(!rs.IsEOF() )
{
CDBVariant v;
memset(&v,0,sizeof(CDBVari
rs.GetFieldValue((short)0,
//always the ERROR here
}
I searched high and low, but so far unable to solve this.
Maybe there's something wrong with my SQL? But
this only happens on SQLServer (I tried different databases on different versions).
Works fine in DB2.
Please help.
ASKER
You're right, I copied the wrong statement, it is:
rs.Open(CRecordset::forwar dOnly,sp_t ext,CRecor dset::read Only);
And yes, I do check the return value, and I see number of records returned in the rs properties.
rs.Open(CRecordset::forwar
And yes, I do check the return value, and I see number of records returned in the rs properties.
OK, and when you open the Data Set Visualizer in VS (just hover over the record set in the debugger and click on the magnifier symbol), do you get the results that you expected n terms of that query?
ASKER
Yes, exactly what is expected. Same number of rows if I run the same query in any SQL program.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bo other solution
Open in new window
really seems wrong, all versions of 'CRecordset::Open()' take 'nOpenType' as their 1st parameter and the SQL statement as the 2nd, see the docs at http://msdn.microsoft.com/en-us/library/1hkkwdf0%28v=vs.120%29.aspx
Also, what is the return value? Are you checking that one before calling 'GetFieldValue()'?