Database problem in vc++(ODBC)
-
hello @all, i have an access data base and a dialogbased program. to connect the program with the data base i used odbc. Then I have a CRecordset class for the data base. Finally I want to register now something into my data base. I make an object of the data base: CDatabase db; db.Open(); Now I want, that the first line of the column x has the value 1. db.m_x=1; (i tried that, but it doesn´t work) what´s wrong? Thank you in advance.
-
hello @all, i have an access data base and a dialogbased program. to connect the program with the data base i used odbc. Then I have a CRecordset class for the data base. Finally I want to register now something into my data base. I make an object of the data base: CDatabase db; db.Open(); Now I want, that the first line of the column x has the value 1. db.m_x=1; (i tried that, but it doesn´t work) what´s wrong? Thank you in advance.
there are 2 way to do what you want. 1) add new class to your project derived from CRecordset and in wizard get the table you want. then work through this class CMySet set(&db); set.Open(); set.AddNew(); // or set.Edit(); set.m_x=1; set.Update(); ... etc... 2) use SQL-queries db.ExecuteSQL(strSQL); Dmitry Timin
-
there are 2 way to do what you want. 1) add new class to your project derived from CRecordset and in wizard get the table you want. then work through this class CMySet set(&db); set.Open(); set.AddNew(); // or set.Edit(); set.m_x=1; set.Update(); ... etc... 2) use SQL-queries db.ExecuteSQL(strSQL); Dmitry Timin
thanks for reply. what do you mean with: add new class to your project derived from CRecordset and in wizard get the table you want? :~ normaly i make it like this: i add a new class in my project (CRecordset, name: CDatabase) and choose the table i want. then i make this:
CDatabase db; db.Open(); db.Edit(); db.m_x=1; db.Update(); db.Close();
i get the error in my program, that there is no current data record. then i tried you second idea use SQL-queries db.ExecuteSQL(strSQL); but it doesn´t work, because CRecordset doesn´t know 'ExecuteSQL(...);', i think. please can you help me? -
thanks for reply. what do you mean with: add new class to your project derived from CRecordset and in wizard get the table you want? :~ normaly i make it like this: i add a new class in my project (CRecordset, name: CDatabase) and choose the table i want. then i make this:
CDatabase db; db.Open(); db.Edit(); db.m_x=1; db.Update(); db.Close();
i get the error in my program, that there is no current data record. then i tried you second idea use SQL-queries db.ExecuteSQL(strSQL); but it doesn´t work, because CRecordset doesn´t know 'ExecuteSQL(...);', i think. please can you help me?do not name your class CDatabase, because CDatabase is a MFC-class and it's the best way to connect to database through CDatabase. then you create CRecordset-derived class and pass a pointer to database as a parameter. ExecuteSQL(...) is a method of MFC CDatabase class. class CMyApp: public CWinApp { CDatabase m_db; }; BOOL CMyApp::InitInstance() { m_db.Open(...); } void CMyView::Func1() // or something else { CMySet set(&theApp.m_db); set.Open(...); // etc... } Dmitry Timin