什么意思?
#include <afxdao.h>然后定义对象不行吗,这可是MFC的类呀。

解决方案 »

  1.   

    用sql是最快的; CDaoDatabase * pdata = NULL;
    openDatabase(&pdata,StockPath);//Stockpath为数据库路径
    CDaoRecordset rs(pdata); 
    CString tempstr =  "Select * from Font ";
    try
    {
    rs.Open(dbOpenDynaset,tempstr);
    }
    catch(CDaoException *e)
    {
    e->Delete();
    return false;
    }
    int openDatabase(CDaoDatabase **ppDatabase, CString fileName,
      BOOL bReportNoOpen /* = TRUE */)
    {
    // initialize success indicator
    int nReturnCode = 1; // close and delete if necessary
    if (*ppDatabase != NULL)
    {
    if ((*ppDatabase)->IsOpen())
    closeDatabase(ppDatabase);
    delete *ppDatabase;
    } // construct new database
    *ppDatabase = new CDaoDatabase; // failed to allocate
    if (ppDatabase == NULL)
    return -1; // fatal error // now open the database object with error checking try
    {
    (*ppDatabase)->Open(fileName);
    }
    catch (CDaoException *e)
    {
    // special case--couldn't find the file, so it may be because
    // user specified a new file to open
    if (e->m_pErrorInfo->m_lErrorCode == 3024)
    {
    if (bReportNoOpen)
    {
    // create a message to display
    CString message = _T("打开数据库失败,出现异常:");
    message += e->m_pErrorInfo->m_strDescription; // output status
    AfxMessageBox(message);
    } // indicate failure but not fatal
    nReturnCode = 0;
    }
    else // other type of DAO exception--always report
    {
    // create a message to display
    CString message = _T("打开数据库失败,出现异常:");
    message += e->m_pErrorInfo->m_strDescription; // output status
    AfxMessageBox(message); // indicate fatal error
    nReturnCode = -1;
    } // not rethrowing, so delete exception
    e->Delete(); delete *ppDatabase;
    *ppDatabase = NULL;
    }
    catch (CMemoryException *e)
    {
    // output status
    AfxMessageBox(_T("Failed to open database--Memory exception thrown.")); // not rethrowing, so delete exception
    e->Delete(); delete *ppDatabase;
    *ppDatabase = NULL; // indicate fatal error
    nReturnCode = -1;
    } return nReturnCode;
    }