c++.mfc - ODBC Recordset
- Mike Comperchio (55/55) Jan 20 2003 I'm SNAFU....I want to use MFC CDatabase/CRecordset along with an
I'm SNAFU....I want to use MFC CDatabase/CRecordset along with an ODBCRecordset wrapper that I got from CodeProject. If I just use CRecordset thus: CDatabase * pDatabase = new CDatabase; ASSERT(pDatabase); pDatabase->OpenEx("DSN=work"); if(pDatabase->IsOpen()){ cout << "opening recordset" << endl; CRecordset *pMyset = new CRecordset(pDatabase); ASSERT(pMyset); pMyset->Open(CRecordset::forwardOnly,"Select * from contacts"); if(pMyset->IsOpen()){ CString strOut; while (!pMyset->IsEOF()){ pMyset->GetFieldValue(2,strOut); cout << strOut << endl; pMyset->MoveNext(); } } } everything works fine. When I include the wrapper class which is declared as class CODBCRecordset : public CRecordset{ other stuff in here... }; this ctor....(I pass in a valid, open database... CODBCRecordset::CODBCRecordset( CDatabase* pDatabase /*= NULL*/ ) : CRecordset( pDatabase ) { m_fields = NULL; m_AllocatedFields = 0; } this code (the overridden CRecordset::Open) does not work... // Open the recordset // lpszSQL is a SQL statement that returns recordset // e.g. SELECT * FROM tablename // nOpentype is CRecordset open type, see CRecordset::Open() // dwOptions is CRecordset options, see CRecordset::Open() BOOL CODBCRecordset::Open( LPCTSTR lpszSQL, UINT nOpenType, /*=AFX_DB_USE_DEFAULT_TYPE*/ DWORD dwOptions /*= 0*/ ) { // Allocate the maximum possible field info storage // This is managed by CRecordset class m_nFields = 255; m_bNotLoadedFieldsMap = true; BOOL nRes = CRecordset::Open( <------------------- this call doesn't work.... nOpenType, lpszSQL, dwOptions ); return nRes; } I'm confused, this should be simple and straightforward....ARGH!...Any pointers would be appreciated.... Michael
Jan 20 2003