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. SDI using CApp in other Class....

SDI using CApp in other Class....

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelptutorialquestion
2 Posts 2 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.
  • E Offline
    E Offline
    Exceter
    wrote on last edited by
    #1

    This is an SDI Application, I am connecting to the Database using a Dialog box, and m_pConn to TRUE if the connecion is established. I want to use the forced connection but have the error. What I am doing wrong? how to solve this error: BOOL CStform::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here _RecordsetPtr m_pRecordset; CStudentApp *App; _bstr_t bstrQuery("SELECT * FROM StudV"); _variant_t vRecsAffected(0L); try { _CommandPtr m_pCommand; m_pCommand.CreateInstance (__uuidof (Command)); m_pCommand->ActiveConnection = App->m_pConn; // Formerly opened connection pointer m_pCommand->CommandText = "Select * From Student"; //m_pRecordset = App.m_pConn->Execute(bstrQuery, vRecsAffected, adOptionUnspecified); //if (!m_pRecordset->GetadoEOF()) { } } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } error C2248: 'CStudentApp::m_pConn' : cannot access protected member declared in class 'CStudentApp' error C2317: 'try' block starting on line '46' has no catch handlers error C2059: syntax error : 'return' error C2059: syntax error : '}' error C2143: syntax error : missing ';' before '}' error C2059: syntax error : '}'

    J 1 Reply Last reply
    0
    • E Exceter

      This is an SDI Application, I am connecting to the Database using a Dialog box, and m_pConn to TRUE if the connecion is established. I want to use the forced connection but have the error. What I am doing wrong? how to solve this error: BOOL CStform::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here _RecordsetPtr m_pRecordset; CStudentApp *App; _bstr_t bstrQuery("SELECT * FROM StudV"); _variant_t vRecsAffected(0L); try { _CommandPtr m_pCommand; m_pCommand.CreateInstance (__uuidof (Command)); m_pCommand->ActiveConnection = App->m_pConn; // Formerly opened connection pointer m_pCommand->CommandText = "Select * From Student"; //m_pRecordset = App.m_pConn->Execute(bstrQuery, vRecsAffected, adOptionUnspecified); //if (!m_pRecordset->GetadoEOF()) { } } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } error C2248: 'CStudentApp::m_pConn' : cannot access protected member declared in class 'CStudentApp' error C2317: 'try' block starting on line '46' has no catch handlers error C2059: syntax error : 'return' error C2059: syntax error : '}' error C2143: syntax error : missing ';' before '}' error C2059: syntax error : '}'

      J Offline
      J Offline
      Joan M
      wrote on last edited by
      #2

      there are some things to consider: 1. if you are trying to use the code as you've shown us... the main problem is that App is not initialized when you want to access it... 2. if you are trying to get access to the main application object, then the declaration is not correct: you should change CStudentApp *App; for extern CStudentApp StudentApp; doing this you'll be accessing the real application object created in OnInitInstance... 3. as the compiler says the try block has no catch... you should catch the exceptions you want to handle... catch(...) for catching all of them. hope this helps...

      https://www.robotecnik.com freelance robots, PLC and CNC programmer.

      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