SDI using CApp in other Class....
-
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 : '}'
-
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 : '}'
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;
forextern 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...