Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Simple ADO question

Simple ADO question

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasedebugginghelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Willem B
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups