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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. SIMPLE db example

SIMPLE db example

Scheduled Pinned Locked Moved C / C++ / MFC
databasesql-serversysadmintutorialquestion
8 Posts 6 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.
  • J Offline
    J Offline
    JockeP
    wrote on last edited by
    #1

    Hi! I have tried to find a simple way to manipulate a database (in MS Access or MS SQL Server). However, I've not succeeded. I've tried SELECT statements with CRecordset and it works. But it seems like only SELECT statements work. This is what I've tried: CDaoDatabase* m_pDB; CDaoRecordset* m_pRS; m_pDB = new CDaoDatabase; m_pRS = new CDaoRecordset(m_pDB); try { m_pDB->Open("c:\\accessdb\\db1.mdb"); // CString strQuery = _T("SELECT * FROM Table1"); //Works just fine... CString strQuery = _T("INSERT INTO Table1 VALUES ('3', 'Olga')"); //Doesn't work m_pRS->Open(dbOpenDynaset, strQuery); } catch (CDaoException* e) { AfxMessageBox(e->m_pErrorInfo->m_strDescription); e->Delete(); } So how do you add data to a table, modify tables and so on? Cheers, Joachim

    L M B S 4 Replies Last reply
    0
    • J JockeP

      Hi! I have tried to find a simple way to manipulate a database (in MS Access or MS SQL Server). However, I've not succeeded. I've tried SELECT statements with CRecordset and it works. But it seems like only SELECT statements work. This is what I've tried: CDaoDatabase* m_pDB; CDaoRecordset* m_pRS; m_pDB = new CDaoDatabase; m_pRS = new CDaoRecordset(m_pDB); try { m_pDB->Open("c:\\accessdb\\db1.mdb"); // CString strQuery = _T("SELECT * FROM Table1"); //Works just fine... CString strQuery = _T("INSERT INTO Table1 VALUES ('3', 'Olga')"); //Doesn't work m_pRS->Open(dbOpenDynaset, strQuery); } catch (CDaoException* e) { AfxMessageBox(e->m_pErrorInfo->m_strDescription); e->Delete(); } So how do you add data to a table, modify tables and so on? Cheers, Joachim

      L Offline
      L Offline
      l a u r e n
      wrote on last edited by
      #2

      im assuming the 3 in ur insert statement goes into a numeric field in the database table ... if so lose the '' around it ... u only have to quote text fields (and prolly date fields sometimes)


      "even if my world is weird its my world"
      biz stuff   about me

      A 1 Reply Last reply
      0
      • L l a u r e n

        im assuming the 3 in ur insert statement goes into a numeric field in the database table ... if so lose the '' around it ... u only have to quote text fields (and prolly date fields sometimes)


        "even if my world is weird its my world"
        biz stuff   about me

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        No, it's a text field

        L 1 Reply Last reply
        0
        • A Anonymous

          No, it's a text field

          L Offline
          L Offline
          l a u r e n
          wrote on last edited by
          #4

          ok well i use odbc for db stuff but it would seem to me that opening a dynaset on an insert statement wouldnt make sense ... u need to simple execute the statement against the db so prolly look for an .execute type command


          "even if my world is weird its my world"
          biz stuff   about me

          J 1 Reply Last reply
          0
          • L l a u r e n

            ok well i use odbc for db stuff but it would seem to me that opening a dynaset on an insert statement wouldnt make sense ... u need to simple execute the statement against the db so prolly look for an .execute type command


            "even if my world is weird its my world"
            biz stuff   about me

            J Offline
            J Offline
            JockeP
            wrote on last edited by
            #5

            ok thanks, but it need more specific ideas... i'm not that experienced with using vc++ to work with databases

            1 Reply Last reply
            0
            • J JockeP

              Hi! I have tried to find a simple way to manipulate a database (in MS Access or MS SQL Server). However, I've not succeeded. I've tried SELECT statements with CRecordset and it works. But it seems like only SELECT statements work. This is what I've tried: CDaoDatabase* m_pDB; CDaoRecordset* m_pRS; m_pDB = new CDaoDatabase; m_pRS = new CDaoRecordset(m_pDB); try { m_pDB->Open("c:\\accessdb\\db1.mdb"); // CString strQuery = _T("SELECT * FROM Table1"); //Works just fine... CString strQuery = _T("INSERT INTO Table1 VALUES ('3', 'Olga')"); //Doesn't work m_pRS->Open(dbOpenDynaset, strQuery); } catch (CDaoException* e) { AfxMessageBox(e->m_pErrorInfo->m_strDescription); e->Delete(); } So how do you add data to a table, modify tables and so on? Cheers, Joachim

              M Offline
              M Offline
              Michael P Butler
              wrote on last edited by
              #6

              Do you really need to use DAO. ADO is a lot easier. Check out this link for some good examples. http://www.codeproject.com/database/#ADO[^] Michael Wonder Woman, Wonder Woman. All the world's waiting for you, and the power you possess. In your satin tights, Fighting for your rights And the old Red, White and Blue.

              1 Reply Last reply
              0
              • J JockeP

                Hi! I have tried to find a simple way to manipulate a database (in MS Access or MS SQL Server). However, I've not succeeded. I've tried SELECT statements with CRecordset and it works. But it seems like only SELECT statements work. This is what I've tried: CDaoDatabase* m_pDB; CDaoRecordset* m_pRS; m_pDB = new CDaoDatabase; m_pRS = new CDaoRecordset(m_pDB); try { m_pDB->Open("c:\\accessdb\\db1.mdb"); // CString strQuery = _T("SELECT * FROM Table1"); //Works just fine... CString strQuery = _T("INSERT INTO Table1 VALUES ('3', 'Olga')"); //Doesn't work m_pRS->Open(dbOpenDynaset, strQuery); } catch (CDaoException* e) { AfxMessageBox(e->m_pErrorInfo->m_strDescription); e->Delete(); } So how do you add data to a table, modify tables and so on? Cheers, Joachim

                B Offline
                B Offline
                bryce
                wrote on last edited by
                #7

                JockeP wrote: ("INSERT INTO Table1 VALUES ('3', 'Olga')"); INSERT INTO Table1 (Field1, Field2) VALUES VALUES ('3', 'Olga')"); where field1 and field2 are obviously part of your table (you didnt tell us the structure of your table) Bryce

                1 Reply Last reply
                0
                • J JockeP

                  Hi! I have tried to find a simple way to manipulate a database (in MS Access or MS SQL Server). However, I've not succeeded. I've tried SELECT statements with CRecordset and it works. But it seems like only SELECT statements work. This is what I've tried: CDaoDatabase* m_pDB; CDaoRecordset* m_pRS; m_pDB = new CDaoDatabase; m_pRS = new CDaoRecordset(m_pDB); try { m_pDB->Open("c:\\accessdb\\db1.mdb"); // CString strQuery = _T("SELECT * FROM Table1"); //Works just fine... CString strQuery = _T("INSERT INTO Table1 VALUES ('3', 'Olga')"); //Doesn't work m_pRS->Open(dbOpenDynaset, strQuery); } catch (CDaoException* e) { AfxMessageBox(e->m_pErrorInfo->m_strDescription); e->Delete(); } So how do you add data to a table, modify tables and so on? Cheers, Joachim

                  S Offline
                  S Offline
                  Solomon Wu
                  wrote on last edited by
                  #8

                  Pls Using: CDaoDatabase::Execute Learning and Working

                  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