This question has a stupid title but let me tell you what's on my

I inserted some Database tables into my project through making
a new class (derived from CDaoRecordset) for each table.

Then I added variables (each representing one table) in my main
code and open the tables through varname.Open. This is quite easy
and convenient. Now my problem is that I want a user to choose
the database on his computer (with a different path than on mine).
I use CFileDilaog and CDaoDatabase to open a database but
I do not know how to insert this new connection into my table
classe / variables. Anyone know how?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StapmanAuthor Commented:
Edited text of question.
If you have built classes with member variables to handle the fields in tables via ClassWizard, the fields are bound to the member variables and are handled through ODBC - they reference the database you selected specifically. If you want to use other databases, you will have to manually select the network path, construct a CDatabase object, open it, construct a CDaoRecordset object, open it with a SQL statement, and navigate through it while manually retrieving values from the fields....
StapmanAuthor Commented:
That's seems too to be much work. There must be an easier way.

My code snip (class declaration):

class db_table : public CDaoRecordset
    db_table(CDaoDatabase* pDatabase =NULL);

    long      m_id1;
    long      m_id2;

    virtual CString GetDefaultDBName();
    virtual CString GetDefaultSQL();
    virtual void DoFieldExchange(CDaoFieldExchange* pFX);

#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;

Now the variable declaration in the header file of my main.cpp:

db_table m_db_table;


Maybe  I should change the GetDefaultDBName() to a global path variable.....???
Read the documentation of both GetDefaultSQL and GetDefaultDbName and take a look at the following code:

CString CAgentSet::GetDefaultConnect()
      CString sConnectionString =
            ((CAgentApp*) AfxGetApp())->m_pParams->GetDbConnectionString();

      ASSERT (sConnectionString!=_T(""));
      if (sConnectionString.IsEmpty())
            sConnectionString = _T("ODBC;");
      return sConnectionString;

CString CAgentSet::GetDefaultSQL()
      return _T("[Agents]");

CAgentSet is the bounded class. In my case GetDefaultDbName() queries the owning application to get the DB name (quite ugly). GetDefaultSQL returns the name of the table. You can change it to return a dynamic table name.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StapmanAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.