Solved

CRecordset "Invalid Descriptor Index "

Posted on 2014-04-15
6
472 Views
Last Modified: 2014-04-22
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(""),FALSE,FALSE,LPCTSTR(sDsn));
CRecordset rs( pDatabase );
rs.m_bUseODBCCursorLib = TRUE;
BOOL iReturn = rs.Open(SQL ,CRecordset::forwardOnly,CRecordset::readOnly);
while(!rs.IsEOF() )
{
    CDBVariant v;
    memset(&v,0,sizeof(CDBVariant));
            
  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.
0
Comment
Question by:trustworthy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 40002070
Is that really your actual code? I am asking because

BOOL iReturn = rs.Open(SQL ,CRecordset::forwardOnly,CRecordset::readOnly);

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()'?
0
 

Author Comment

by:trustworthy
ID: 40002149
You're right, I copied the wrong statement, it is:

rs.Open(CRecordset::forwardOnly,sp_text,CRecordset::readOnly);

And yes, I do check the return value, and I see number of records returned in the rs properties.
0
 
LVL 86

Expert Comment

by:jkr
ID: 40003107
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?
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:trustworthy
ID: 40003726
Yes, exactly what is expected. Same number of rows if I run the same query in any SQL program.
0
 

Accepted Solution

by:
trustworthy earned 0 total points
ID: 40007642
I can't figure this out, so I decided not to use CRecordset at all
0
 

Author Closing Comment

by:trustworthy
ID: 40014367
Bo other solution
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question