MFC & CResordset Open() fails: Driving me nuts!
Here's my complete code, which according to everything I've seen
bool ok = db.Open( szDSN ); // szDSN contains a valid ODBC name, and
this returns true
CRecordset rs( &db );
rs.Open( AFX_DB_USE_DEFAULT_TYPE, _T("Select * from myTable") );
ok is true, and rs.Open throws an exception because no rows are
returned. (There's a MoveNext() that fails in Open()). The select
statement returns a few rows when ran from SQL Analyzer.
If the reason is that I do not bind parameters, I do not want to. I am
trying to build a generic way to have a SQL statement fill a
CRecordset, in which I will get the column names after it's filled.
1- There's something wrong with my code above, or
2- I'm going at this the wrong way. Could you please recommend a
different tool/class to do this? My bounds are VC++ 6 and MFC, MS SQL
2005. I want to make no assumption on the returned fields before
opening the dataset.
Re: MFC & CResordset Open() fails: Driving me nuts!
I'm not an expert on this, but here's a few possible pointers:
1. You may need to derive a class from CRecordset to make this work.
2. I built a class to extract information in this sort of way - it may
give you some ideas ([url]http://www.Codeproject.com/KB/database/[/url]
3. Is the table name correct? Sometimes you need to add in the owner,
Hope that helps