Simple ADO question
-
It doesn't work.... I make a ADO connection with my database in my app:
**myapp.cpp:** // initialisation/constructor void CMyApp::CMyApp() { try { HRESULT hr = m_pConn.CreateInstance (__uuidof (Connection)); if (FAILED (hr)) { AfxMessageBox ("Can't create intance of Connection"); } if (FAILED (m_pConn->Open (_bstr_t ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = Database.mdb"), _bstr_t (""), _bstr_t (""), adModeUnknown))) { AfxMessageBox ("Can't open datasource"); } } catch ( _com_error &e ) { _bstr_t bstrSource (e.Source()); _bstr_t bstrDescription (e.Description()); TRACE ( "Exception thrown for classes generated by #import" ); TRACE ( "\tCode = %08lx\n", e.Error ()); TRACE ( "\tCode meaning = %s\n", e.ErrorMessage ()); TRACE ( "\tSource = %s\n", (LPCTSTR) bstrSource); TRACE ( "\tDescription = %s\n", (LPCTSTR) bstrDescription); AfxMessageBox ((LPCTSTR) bstrDescription); } catch (...) { TRACE ( "*** Unhandled Exception ***" ); } }
Header file:**myapp.h:** CDatabaseClass AppDatabase; _ConnectionPtr m_pConn;
Then i send the pointer(m_pConn) to a new made class and check the database:myapp.cpp: void CMyApp::CheckLogin() { AppDatabase.m_pConn = m_pConn; if (AppDatabase.CheckLogin(Name, Pass)) { AfxMessageBox("login correct"); } }
Check Function(here it goes wrong):**DatabaseClass.cpp:** bool CDatabaseClass::CheckLogin(CString Naam, CString Pass) { bool login; try { CString tmpNaam, tmpPass; Naam.Replace("'", " "); Pass.Replace("'", " "); login = FALSE; _CommandPtr pCommand; pCommand.CreateInstance (__uuidof (Command)); pCommand->ActiveConnection = m_pConn; pCommand->CommandText = "Select * From Gebruikers;"; _RecordsetPtr pRecordset; pRecordset.CreateInstance (__uuidof (Recordset)); pRecordset->CursorLocation = adUseClient; pRecordset->Open ((IDispatch *) pCommand, vtMissing, adOpenForwardOnly, adLockReadOnly, adCmdUnknown); // Here it goes wrong!!! while (!pRecordset->GetadoEOF()) { tmpNaam = (char *) (_bstr_t) pRecordset->Fields->GetItem("Naam")->Value; tmpPass = (char *) (_bstr_t) pRecordset->Fields->GetItem("Pass")->Value; if {(tmpNaam == Naam) && (tmpPass == Pass)) { login = TRUE; } pRecordset->MoveNext(); } pRecordset->Close (); } catch( _com_error &e ) { _bstr_t bstrSou