?
Solved

CRecordset "Invalid Descriptor Index "

Posted on 2014-04-15
6
Medium Priority
?
493 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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

770 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