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. Database problem in vc++(ODBC)

Database problem in vc++(ODBC)

Scheduled Pinned Locked Moved C / C++ / MFC
databasec++helpquestion
4 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.
  • M Offline
    M Offline
    MFC is the Best
    wrote on last edited by
    #1

    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.

    D 1 Reply Last reply
    0
    • M MFC is the Best

      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.

      D Offline
      D Offline
      dima_t
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • D dima_t

        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

        M Offline
        M Offline
        MFC is the Best
        wrote on last edited by
        #3

        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?

        D 1 Reply Last reply
        0
        • M MFC is the Best

          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?

          D Offline
          D Offline
          dima_t
          wrote on last edited by
          #4

          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

          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