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. Why I cannot have a ListControl in a CRecordView derived class?

Why I cannot have a ListControl in a CRecordView derived class?

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasehelpquestion
32 Posts 3 Posters 2 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.
  • L Larry Mills Sr

    Yes!

    A C++ programming language novice, but striving to learn

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #8

    So then what's the error?

    "One man's wage rise is another man's price increase." - Harold Wilson

    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

    L 1 Reply Last reply
    0
    • D David Crow

      So then what's the error?

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      L Offline
      L Offline
      Larry Mills Sr
      wrote on last edited by
      #9

      David it doesn't give an error, it just crashes.

      A C++ programming language novice, but striving to learn

      D 1 Reply Last reply
      0
      • L Larry Mills Sr

        David it doesn't give an error, it just crashes.

        A C++ programming language novice, but striving to learn

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #10

        Larry Mills Sr wrote:

        ...it just crashes.

        Assertion, exception, what?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        L 1 Reply Last reply
        0
        • D David Crow

          Larry Mills Sr wrote:

          ...it just crashes.

          Assertion, exception, what?

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          L Offline
          L Offline
          Larry Mills Sr
          wrote on last edited by
          #11

          //This crashes because as you indicated the window has not been created yet: void CCookItDBView::OnInitialUpdate() {      m_pSet = &GetDocument()->m_CookItDBSet;      SetColumsIngred();      CRecordView::OnInitialUpdate(); } // THIS IS CORRECT   IT WORKS NOW void CCookItDBView::OnInitialUpdate() {      m_pSet = &GetDocument()->m_CookItDBSet;      CRecordView::OnInitialUpdate();      SetColumsIngred(); } I didn't understand you previous comment until in debug I caught it. Thanks David. Question: I have several "Tables" in the database that hopefully will point me to data contained in other tables that are not presently linked in the RecordSet. For example: Table "RecipeData" is not linked in the RecordSet (I didn't select it when I selected the Tables) can I still do this:   CString str = m_pSet->[RecordDate].Recipe;

          A C++ programming language novice, but striving to learn

          D 1 Reply Last reply
          0
          • L Larry Mills Sr

            //This crashes because as you indicated the window has not been created yet: void CCookItDBView::OnInitialUpdate() {      m_pSet = &GetDocument()->m_CookItDBSet;      SetColumsIngred();      CRecordView::OnInitialUpdate(); } // THIS IS CORRECT   IT WORKS NOW void CCookItDBView::OnInitialUpdate() {      m_pSet = &GetDocument()->m_CookItDBSet;      CRecordView::OnInitialUpdate();      SetColumsIngred(); } I didn't understand you previous comment until in debug I caught it. Thanks David. Question: I have several "Tables" in the database that hopefully will point me to data contained in other tables that are not presently linked in the RecordSet. For example: Table "RecipeData" is not linked in the RecordSet (I didn't select it when I selected the Tables) can I still do this:   CString str = m_pSet->[RecordDate].Recipe;

            A C++ programming language novice, but striving to learn

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #12

            Yes, you can reference whatever tables you want in the GetDefaultSQL() method. Make sure that the fields in the query match the order of the associated variables in the DoFieldExchange() method.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            L 1 Reply Last reply
            0
            • D David Crow

              Yes, you can reference whatever tables you want in the GetDefaultSQL() method. Make sure that the fields in the query match the order of the associated variables in the DoFieldExchange() method.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              L Offline
              L Offline
              Larry Mills Sr
              wrote on last edited by
              #13

              David, I tried to write to the DB and I get an error "The RecordSet is read only."   How do I change that?

              A C++ programming language novice, but striving to learn

              D 1 Reply Last reply
              0
              • L Larry Mills Sr

                David, I tried to write to the DB and I get an error "The RecordSet is read only."   How do I change that?

                A C++ programming language novice, but striving to learn

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #14

                If your query is joining multiple tables, it cannot be updated (i.e., read-only).

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                L 2 Replies Last reply
                0
                • D David Crow

                  If your query is joining multiple tables, it cannot be updated (i.e., read-only).

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  L Offline
                  L Offline
                  Larry Mills Sr
                  wrote on last edited by
                  #15

                  So how do I update, ie Read, Write or delete an individual table's record. Do I have to create a DSN for each table or what?

                  A C++ programming language novice, but striving to learn

                  D 1 Reply Last reply
                  0
                  • L Larry Mills Sr

                    So how do I update, ie Read, Write or delete an individual table's record. Do I have to create a DSN for each table or what?

                    A C++ programming language novice, but striving to learn

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #16

                    Larry Mills Sr wrote:

                    So how do I update, ie Read, Write or delete an individual table's record.

                    Yes. Those tables should all be linked together via a primary/foreign key.

                    Larry Mills Sr wrote:

                    Do I have to create a DSN for each table or what?

                    No, but you may end up with several recordset classes.

                    "One man's wage rise is another man's price increase." - Harold Wilson

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    L 1 Reply Last reply
                    0
                    • D David Crow

                      Larry Mills Sr wrote:

                      So how do I update, ie Read, Write or delete an individual table's record.

                      Yes. Those tables should all be linked together via a primary/foreign key.

                      Larry Mills Sr wrote:

                      Do I have to create a DSN for each table or what?

                      No, but you may end up with several recordset classes.

                      "One man's wage rise is another man's price increase." - Harold Wilson

                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                      L Offline
                      L Offline
                      Larry Mills Sr
                      wrote on last edited by
                      #17

                      David, I don't understand your response. The tables are all loaded, but I cannot write or delete any records in them. How exactly do I write to one of the tables to add a new record? How dom I set CanUpdate() and CanAppend() to TRUE. Nowhere in the Wizzard supplied Recordset class is there an "Open(....)" statement so I can change anything, so just how do I get to write tothe database?

                      A C++ programming language novice, but striving to learn

                      D 1 Reply Last reply
                      0
                      • L Larry Mills Sr

                        David, I don't understand your response. The tables are all loaded, but I cannot write or delete any records in them. How exactly do I write to one of the tables to add a new record? How dom I set CanUpdate() and CanAppend() to TRUE. Nowhere in the Wizzard supplied Recordset class is there an "Open(....)" statement so I can change anything, so just how do I get to write tothe database?

                        A C++ programming language novice, but striving to learn

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #18

                        Larry Mills Sr wrote:

                        ...but I cannot write or delete any records in them

                        Make sure the DSN, the CDatabase object, and the CRecordset object are all opened correctly (i.e., non read-only).

                        Larry Mills Sr wrote:

                        How exactly do I write to one of the tables to add a new record?

                        Use the CRecordset::AddNew() followed by CRecordset::Update().

                        Larry Mills Sr wrote:

                        Nowhere in the Wizzard supplied Recordset class is there an "Open(....)" statement...

                        See here. While it does not do any updating, you might check out this[^] article.

                        "One man's wage rise is another man's price increase." - Harold Wilson

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        L 1 Reply Last reply
                        0
                        • D David Crow

                          Larry Mills Sr wrote:

                          ...but I cannot write or delete any records in them

                          Make sure the DSN, the CDatabase object, and the CRecordset object are all opened correctly (i.e., non read-only).

                          Larry Mills Sr wrote:

                          How exactly do I write to one of the tables to add a new record?

                          Use the CRecordset::AddNew() followed by CRecordset::Update().

                          Larry Mills Sr wrote:

                          Nowhere in the Wizzard supplied Recordset class is there an "Open(....)" statement...

                          See here. While it does not do any updating, you might check out this[^] article.

                          "One man's wage rise is another man's price increase." - Harold Wilson

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          L Offline
                          L Offline
                          Larry Mills Sr
                          wrote on last edited by
                          #19

                          David Crow wrote: Make sure the DSN, the CDatabase object, and the CRecordset object are all opened correctly (i.e., non read-only). David, that's what I'm trying to found out how to do! All I've done since the the Wizard create the Recordset class is compile the program, which did so correctly. Am I supposed to do a database "Open(....) statement somewhere. I didn't see that in your I "Invoice" program anywhere. I simply don't know what to do at this point. Help please!

                          A C++ programming language novice, but striving to learn

                          D 1 Reply Last reply
                          0
                          • L Larry Mills Sr

                            David Crow wrote: Make sure the DSN, the CDatabase object, and the CRecordset object are all opened correctly (i.e., non read-only). David, that's what I'm trying to found out how to do! All I've done since the the Wizard create the Recordset class is compile the program, which did so correctly. Am I supposed to do a database "Open(....) statement somewhere. I didn't see that in your I "Invoice" program anywhere. I simply don't know what to do at this point. Help please!

                            A C++ programming language novice, but striving to learn

                            D Offline
                            D Offline
                            David Crow
                            wrote on last edited by
                            #20

                            Larry Mills Sr wrote:

                            David, that's what I'm trying to found out how to do!

                            Does the query contain any JOINs?

                            Larry Mills Sr wrote:

                            Am I supposed to do a database "Open(....) statement somewhere.

                            It's not necessary since CRecordset also has an Open() method.

                            "One man's wage rise is another man's price increase." - Harold Wilson

                            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                            L 1 Reply Last reply
                            0
                            • D David Crow

                              Larry Mills Sr wrote:

                              David, that's what I'm trying to found out how to do!

                              Does the query contain any JOINs?

                              Larry Mills Sr wrote:

                              Am I supposed to do a database "Open(....) statement somewhere.

                              It's not necessary since CRecordset also has an Open() method.

                              "One man's wage rise is another man's price increase." - Harold Wilson

                              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                              L Offline
                              L Offline
                              Larry Mills Sr
                              wrote on last edited by
                              #21

                              David, I don't do any SQL statements. I'm supposing the recordset is initialized properly on execution. It does read fine(the data is in the varables. But it will NOT allow me to write a record to the database. I did this: BOOL B = m_pSet->CanAppend(); and BOOL f = m_pSet->CanUpdate(); and both show "0" values. I don't know how to make it "CRecordset::none" which is supposed to make it writable, but it doesn't.   Another thing, in using Windows Explorer I right click on the folder and the "Read Only" box is filled in; I clear it and click the applly button, I select the apply to subfolders and files and click "OK" and no activity is shown I click "OK" and immediately click on property again and "Read Only" is again filled in. I go through the same thing again with the same results.   I am the only User of this computer and all listed Users(ie, SYSTEM, Administrator, User all have "Full Control" security selected. What gives?

                              A C++ programming language novice, but striving to learn

                              D 1 Reply Last reply
                              0
                              • L Larry Mills Sr

                                David, I don't do any SQL statements. I'm supposing the recordset is initialized properly on execution. It does read fine(the data is in the varables. But it will NOT allow me to write a record to the database. I did this: BOOL B = m_pSet->CanAppend(); and BOOL f = m_pSet->CanUpdate(); and both show "0" values. I don't know how to make it "CRecordset::none" which is supposed to make it writable, but it doesn't.   Another thing, in using Windows Explorer I right click on the folder and the "Read Only" box is filled in; I clear it and click the applly button, I select the apply to subfolders and files and click "OK" and no activity is shown I click "OK" and immediately click on property again and "Read Only" is again filled in. I go through the same thing again with the same results.   I am the only User of this computer and all listed Users(ie, SYSTEM, Administrator, User all have "Full Control" security selected. What gives?

                                A C++ programming language novice, but striving to learn

                                D Offline
                                D Offline
                                David Crow
                                wrote on last edited by
                                #22

                                Larry Mills Sr wrote:

                                David, I don't do any SQL statements.

                                In your CRecordset-dervied class, what does the GetDefaultSQL() method look like? Are you using a DSN? If so, have you checked it for any "read only" properties? Are you calling CDatabase::Open()? If so, what is the third argument being sent to it?

                                "One man's wage rise is another man's price increase." - Harold Wilson

                                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                L 1 Reply Last reply
                                0
                                • D David Crow

                                  Larry Mills Sr wrote:

                                  David, I don't do any SQL statements.

                                  In your CRecordset-dervied class, what does the GetDefaultSQL() method look like? Are you using a DSN? If so, have you checked it for any "read only" properties? Are you calling CDatabase::Open()? If so, what is the third argument being sent to it?

                                  "One man's wage rise is another man's price increase." - Harold Wilson

                                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                  L Offline
                                  L Offline
                                  Larry Mills Sr
                                  wrote on last edited by
                                  #23

                                  Here's the code: CString CMyDB::GetDefaultConnect() {      return _T("DBQ=C:\\CookIt\\Program\\DataBases\\DB\\CookIt.mdb;DefaultDir=C:\\CookIt\\Program\\DataBases\\DB;Driver={Driver do Microsoft Access (*.mdb)};DriverId=25;FIL=MS Access;FILEDSN=C:\\CookIt\\Program\\DataBases\\DB\\CookIt.mdb.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"); } CString CMyDB::GetDefaultSQL() {      return _T("[ApeData],[BreadData],[CakeData],[CandyData],[CookieData],[DrinkData],[FruitData],[MeatData],[PastryData],[PieData],[PudData],[Recipe],[SaladData],[SauceData],[SelRecipe],[SoupData],[Special2Pg1],[Special2Pg2],[Special2Pg3],[Special2Pg4],[Special2Pg5],[Special2Pg7],[SpecialPg1],[SpecialPg2],[SpecialPg3],[SpecialPg4],[SpecialPg5],[SpecialPg6],[SpecialPg7],[VegData]"); } Here's some more code: void CCookItDBView::OnInitialUpdate()      {      m_pSet = &GetDocument()->m_CookItDBSet;      m_pSet->Open(CRecordset::dynaset,0,CRecordset::none );           BOOL B = m_pSet->CanAppend();      BOOL e = m_pSet->CanUpdate();             } Yes I am using DSN and no I don't use a CDatabase object(because I don't know how) I don't know whaqt to put in the Cdatabase.Open(...,...,...) statement. I checked carefully when I did the "add class" and OBDC dialog and the "Read Only" box was left unselected as was the "Execute" box

                                  A C++ programming language novice, but striving to learn

                                  D 1 Reply Last reply
                                  0
                                  • L Larry Mills Sr

                                    Here's the code: CString CMyDB::GetDefaultConnect() {      return _T("DBQ=C:\\CookIt\\Program\\DataBases\\DB\\CookIt.mdb;DefaultDir=C:\\CookIt\\Program\\DataBases\\DB;Driver={Driver do Microsoft Access (*.mdb)};DriverId=25;FIL=MS Access;FILEDSN=C:\\CookIt\\Program\\DataBases\\DB\\CookIt.mdb.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"); } CString CMyDB::GetDefaultSQL() {      return _T("[ApeData],[BreadData],[CakeData],[CandyData],[CookieData],[DrinkData],[FruitData],[MeatData],[PastryData],[PieData],[PudData],[Recipe],[SaladData],[SauceData],[SelRecipe],[SoupData],[Special2Pg1],[Special2Pg2],[Special2Pg3],[Special2Pg4],[Special2Pg5],[Special2Pg7],[SpecialPg1],[SpecialPg2],[SpecialPg3],[SpecialPg4],[SpecialPg5],[SpecialPg6],[SpecialPg7],[VegData]"); } Here's some more code: void CCookItDBView::OnInitialUpdate()      {      m_pSet = &GetDocument()->m_CookItDBSet;      m_pSet->Open(CRecordset::dynaset,0,CRecordset::none );           BOOL B = m_pSet->CanAppend();      BOOL e = m_pSet->CanUpdate();             } Yes I am using DSN and no I don't use a CDatabase object(because I don't know how) I don't know whaqt to put in the Cdatabase.Open(...,...,...) statement. I checked carefully when I did the "add class" and OBDC dialog and the "Read Only" box was left unselected as was the "Execute" box

                                    A C++ programming language novice, but striving to learn

                                    D Offline
                                    D Offline
                                    David Crow
                                    wrote on last edited by
                                    #24

                                    Larry Mills Sr wrote:

                                    CString CMyDB::GetDefaultConnect() { return _T("DBQ=C:\\CookIt\\Program\\DataBases\\DB\\CookIt.mdb;DefaultDir=C:\\CookIt\\Program\\DataBases\\DB;Driver={Driver do Microsoft Access (*.mdb)};DriverId=25;FIL=MS Access;FILEDSN=C:\\CookIt\\Program\\DataBases\\DB\\CookIt.mdb.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"); }

                                    This looks odd. Mine always have the form:

                                    return _T("ODBC;DSN=Gymnastics");

                                    All of those other values (e.g., database, sizes) are defined in the DSN itself. In my CDocument class, I have a CDatabase object. Anytime I need access to it, I use:

                                    CDatabase *CMyDoc::GetDatabase( void )
                                    {
                                    if (! m_rDatabase.IsOpen())
                                    m_rDatabase.Open(NULL, NULL, FALSE, _T("ODBC;DSN=Gymnastics"));

                                    return (&m\_rDatabase);
                                    

                                    }

                                    When I want to add to a table, I use:

                                    CMyRecordset set;
                                    set.m_pDatabase = GetDocument()->GetDatabase();

                                    TRY
                                    {
                                    set.Open();
                                    set.AddNew();
                                    ...
                                    set.Update();
                                    set.Close();
                                    }
                                    CATCH(CDBException, pDBException)
                                    {
                                    AfxMessageBox(pDBException->m_strError);
                                    }
                                    END_CATCH

                                    "One man's wage rise is another man's price increase." - Harold Wilson

                                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                    L 2 Replies Last reply
                                    0
                                    • D David Crow

                                      Larry Mills Sr wrote:

                                      CString CMyDB::GetDefaultConnect() { return _T("DBQ=C:\\CookIt\\Program\\DataBases\\DB\\CookIt.mdb;DefaultDir=C:\\CookIt\\Program\\DataBases\\DB;Driver={Driver do Microsoft Access (*.mdb)};DriverId=25;FIL=MS Access;FILEDSN=C:\\CookIt\\Program\\DataBases\\DB\\CookIt.mdb.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"); }

                                      This looks odd. Mine always have the form:

                                      return _T("ODBC;DSN=Gymnastics");

                                      All of those other values (e.g., database, sizes) are defined in the DSN itself. In my CDocument class, I have a CDatabase object. Anytime I need access to it, I use:

                                      CDatabase *CMyDoc::GetDatabase( void )
                                      {
                                      if (! m_rDatabase.IsOpen())
                                      m_rDatabase.Open(NULL, NULL, FALSE, _T("ODBC;DSN=Gymnastics"));

                                      return (&m\_rDatabase);
                                      

                                      }

                                      When I want to add to a table, I use:

                                      CMyRecordset set;
                                      set.m_pDatabase = GetDocument()->GetDatabase();

                                      TRY
                                      {
                                      set.Open();
                                      set.AddNew();
                                      ...
                                      set.Update();
                                      set.Close();
                                      }
                                      CATCH(CDBException, pDBException)
                                      {
                                      AfxMessageBox(pDBException->m_strError);
                                      }
                                      END_CATCH

                                      "One man's wage rise is another man's price increase." - Harold Wilson

                                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                      L Offline
                                      L Offline
                                      Larry Mills Sr
                                      wrote on last edited by
                                      #25

                                      I copied that stuff from my program.   That's the stuff the wizard produced. I am using VS2008 completely updated. the MS Access database is called "CookIt.mdb" and with the DSN iit is now "CookIt.mdb.dsn"   Is this normal? Now, you state you have a CDatabase in Documents. Do I declare it in the Header?   and how do I get the CRecordset m_pSet set to that database? I may be asking this wrong. The wizard created a CRecordset class called MyDB(I renamed it). How does the database you created in CMyDoc use the recordset that the wizard created? You wrote: m_rDatabase.Open(NULL, NULL, FALSE, _T("ODBC;DSN=Gymnastics")); so if I used your code would mine be: m_rDatabase.Open(NULL, NULL, FALSE, _T("ODBC;DSN=CookIt")); Is this right?

                                      A C++ programming language novice, but striving to learn

                                      D 1 Reply Last reply
                                      0
                                      • D David Crow

                                        Larry Mills Sr wrote:

                                        CString CMyDB::GetDefaultConnect() { return _T("DBQ=C:\\CookIt\\Program\\DataBases\\DB\\CookIt.mdb;DefaultDir=C:\\CookIt\\Program\\DataBases\\DB;Driver={Driver do Microsoft Access (*.mdb)};DriverId=25;FIL=MS Access;FILEDSN=C:\\CookIt\\Program\\DataBases\\DB\\CookIt.mdb.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"); }

                                        This looks odd. Mine always have the form:

                                        return _T("ODBC;DSN=Gymnastics");

                                        All of those other values (e.g., database, sizes) are defined in the DSN itself. In my CDocument class, I have a CDatabase object. Anytime I need access to it, I use:

                                        CDatabase *CMyDoc::GetDatabase( void )
                                        {
                                        if (! m_rDatabase.IsOpen())
                                        m_rDatabase.Open(NULL, NULL, FALSE, _T("ODBC;DSN=Gymnastics"));

                                        return (&m\_rDatabase);
                                        

                                        }

                                        When I want to add to a table, I use:

                                        CMyRecordset set;
                                        set.m_pDatabase = GetDocument()->GetDatabase();

                                        TRY
                                        {
                                        set.Open();
                                        set.AddNew();
                                        ...
                                        set.Update();
                                        set.Close();
                                        }
                                        CATCH(CDBException, pDBException)
                                        {
                                        AfxMessageBox(pDBException->m_strError);
                                        }
                                        END_CATCH

                                        "One man's wage rise is another man's price increase." - Harold Wilson

                                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                        L Offline
                                        L Offline
                                        Larry Mills Sr
                                        wrote on last edited by
                                        #26

                                        I used your code and it says: m_rDatabase.Open(NULL, NULL, FALSE, _T("ODBC;DSN=CookIt.mdb.dsn")); "file not found" if change it to: m_rDatabase.Open(NULL, NULL, FALSE, _T("ODBC;DSN=c:\\CookIt\\Program\\DataBases\\DB\\CookIt.mdb.dsn")); and it gave error: "Data Source name toog long and not found" I finally put the original under GetDefaultConnect(). Id gave an error of "ODBC does not support dynsets" the database was created as 2003 and I used the driver 6.001 which is supposed to work on either dynasets or snapshots? any ideas? I re-created the Recordset this time I selected "snapshot". Now it says "Recordset is read Only"? I don;t understand this!

                                        A C++ programming language novice, but striving to learn

                                        modified on Monday, December 7, 2009 8:32 PM

                                        D 1 Reply Last reply
                                        0
                                        • L Larry Mills Sr

                                          I used your code and it says: m_rDatabase.Open(NULL, NULL, FALSE, _T("ODBC;DSN=CookIt.mdb.dsn")); "file not found" if change it to: m_rDatabase.Open(NULL, NULL, FALSE, _T("ODBC;DSN=c:\\CookIt\\Program\\DataBases\\DB\\CookIt.mdb.dsn")); and it gave error: "Data Source name toog long and not found" I finally put the original under GetDefaultConnect(). Id gave an error of "ODBC does not support dynsets" the database was created as 2003 and I used the driver 6.001 which is supposed to work on either dynasets or snapshots? any ideas? I re-created the Recordset this time I selected "snapshot". Now it says "Recordset is read Only"? I don;t understand this!

                                          A C++ programming language novice, but striving to learn

                                          modified on Monday, December 7, 2009 8:32 PM

                                          D Offline
                                          D Offline
                                          David Crow
                                          wrote on last edited by
                                          #27

                                          Larry Mills Sr wrote:

                                          m_rDatabase.Open(NULL, NULL, FALSE, _T("ODBC;DSN=CookIt.mdb.dsn"));

                                          What name did you give the DSN when you created it? You get there using either Start --> Administrative Tools --> Data Sources (ODBC) Or by typing odbccp32.cpl in the Run box.

                                          "One man's wage rise is another man's price increase." - Harold Wilson

                                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                          L 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