Where is wrong when I try to get the recordset?
-
I am trying to access the StudentTable in an Oracle database, I have set the data source correctly. There is also no errors reported after I built the exe file. but when I ran the exe, I can see the messagebox showing the "connectinon to the database succeeds." In the following step, there is a messagebox with title "Microsoft Visual C++ Runtime Library" showing "Runtime error ...". I don't know where is wrong , here is the code, who could tell me where is wrong? Thanks. BOOL flag=FALSE; flag=m_db.Open("MyDSN",FALSE,FALSE,"ODBC;UID=user1;PWD=userpwd",TRUE); //m_db is a CDatabase member object. if(flag) AfxMessageBox("connectinon to the database succeeds."); else AfxMessageBox("connectinon to the database failed."); CRecordset rs(&m_db); try { if(rs.IsOpen()) rs.Close(); if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,_T("select * from user1.StudentTable"),CRecordset::readOnly)) AfxMessageBox("Recordset has been opened!"); } catch(CDBException e) { e.ReportError(); AfxMessageBox("Failed to open the recordset"); }
-
I am trying to access the StudentTable in an Oracle database, I have set the data source correctly. There is also no errors reported after I built the exe file. but when I ran the exe, I can see the messagebox showing the "connectinon to the database succeeds." In the following step, there is a messagebox with title "Microsoft Visual C++ Runtime Library" showing "Runtime error ...". I don't know where is wrong , here is the code, who could tell me where is wrong? Thanks. BOOL flag=FALSE; flag=m_db.Open("MyDSN",FALSE,FALSE,"ODBC;UID=user1;PWD=userpwd",TRUE); //m_db is a CDatabase member object. if(flag) AfxMessageBox("connectinon to the database succeeds."); else AfxMessageBox("connectinon to the database failed."); CRecordset rs(&m_db); try { if(rs.IsOpen()) rs.Close(); if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,_T("select * from user1.StudentTable"),CRecordset::readOnly)) AfxMessageBox("Recordset has been opened!"); } catch(CDBException e) { e.ReportError(); AfxMessageBox("Failed to open the recordset"); }
Have you single-stepped through the code to see which statement is causing the error?
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
-
I am trying to access the StudentTable in an Oracle database, I have set the data source correctly. There is also no errors reported after I built the exe file. but when I ran the exe, I can see the messagebox showing the "connectinon to the database succeeds." In the following step, there is a messagebox with title "Microsoft Visual C++ Runtime Library" showing "Runtime error ...". I don't know where is wrong , here is the code, who could tell me where is wrong? Thanks. BOOL flag=FALSE; flag=m_db.Open("MyDSN",FALSE,FALSE,"ODBC;UID=user1;PWD=userpwd",TRUE); //m_db is a CDatabase member object. if(flag) AfxMessageBox("connectinon to the database succeeds."); else AfxMessageBox("connectinon to the database failed."); CRecordset rs(&m_db); try { if(rs.IsOpen()) rs.Close(); if(rs.Open(AFX_DB_USE_DEFAULT_TYPE,_T("select * from user1.StudentTable"),CRecordset::readOnly)) AfxMessageBox("Recordset has been opened!"); } catch(CDBException e) { e.ReportError(); AfxMessageBox("Failed to open the recordset"); }
http://www.codeguru.com/forum/showthread.php?t=314031 Regards, Andrzej Markowski
My Latest ArticlesCCustomBitmapButton: An owner-draw button and a frame for the caption bar, in one class. CCustomTabCtrl: A clone of the Excel tab sheet control.