Using CDaoDatabase class... includes, etc.

What do I need to include and/or link to to use CDaoDatabase objects?  I don't want to have to use the AppWizard for DB support... I'm sure it's easy, but it's a little hard to figure out which files to include, etc.

A little snippet showing how to instantiate and initialize a CDaoDatabase will get an extra 100 points.
Who is Participating?
EssConnect With a Mentor Commented:
#include <afxdao.h> in your stdafx.h file.  Note that if you are using an Access 2000 file as your database you will also need to include AfxGetModuleState()->m_dwVersion = 0x0601 in your InitInstance() function, if you are linking with a shared MFC library.  If you do not do this you will get an error with access 2000 that states "unrecognized database format"  If you are using MFC in a static library you will need to rebuild the MFC library.  Details are on the Micorosft knowledge base.  For other versions you do not need to do this.

To use CDaoDatabase just do the following:

//Open the database
CDaoDatabase database;
// Open a recordset
CDaoRecordset recordset(&database);
// Note the SQL statement takes the form "Select
//<something or *> from FieldName)
recordset.Open(dbOpenDynaset,"SQL statement to get records",0);
COleVariant Value;
//Get Field Values
// Close the recordset and database

Hope this helps!!
smitty1276Author Commented:
I haven't tried it yet, but it should definately get me in the right direction!  Thanks...
You should also include <afxdb.h> for ODBC database support probably.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.