m_database.Open(_T("DBT2"));
CMyRecordset mrd(&m_database);
mrd.Open(CRecordset::dynaset,"select * from szb"); 
CMyRecordset 为自己定义的基于CRecordset的类运行时老是说ODBC数据库不支持动态记录集这个问题如何解决?

解决方案 »

  1.   

    http://www.microsoft.com/china/technet/sql/technote/dat406ef.asp
      

  2.   

    CDatabase的Open函数定义如下:
    virtual BOOL Open( LPCTSTR lpszDSN, BOOL bExclusive = FALSE, BOOL bReadOnly = FALSE, LPCTSTR lpszConnect = “ODBC;”, BOOL bUseCursorLib = TRUE );其中bUseCursorLib 参数的msdn解释如下:
    TRUE if you want the ODBC Cursor Library DLL to be loaded. The cursor library masks some functionality of the underlying ODBC driver, effectively preventing the use of dynasets (if the driver supports them). The only cursors supported if the cursor library is loaded are static snapshots and forward-only cursors. The default value is TRUE. If you plan to create a recordset object directly from CRecordset without deriving from it, you should not load the cursor library.大意是说假如bUseCursorLib为TRUE时,ODBC光标库将被加载。光标库会覆盖ODBC驱动程序的一些功能,有效地阻止动态记录集的使用(假如ODBC驱动程序支持动态记录集的使用的话)。假如光标库被加载唯一的光标支持的是静态快照集和唯一向前的光标。参数默认值是TRUE。假如你直接创建一个CRecordset类对象而不是继承自它,你不应该装载光标库。   因此问题的解决办法是将bUseCursorLib的值设为FALSE。
      

  3.   

    用OpenEx(...)连接数据库,
    例:CDatabase DB;
    CString sLink;
    sLink.Format(_T("DSN=%s;UID=%s;PWD=%s"),sDBSource,sUserName,sPassword);
    DB.OpenEx(sLink,CDatabase::noOdbcDialog);