对了,不用ADO,虽然其操作方便,但太慢了

解决方案 »

  1.   

    ado对个人的要求高一点,但是它是最灵活的,效率也高,
    OLEDB就是建立在ADO的基础之上的
      

  2.   

    http://codeguru.earthweb.com/mfc_database/generic_recordset.shtml
    这篇文章是对CDaoRecordset扩充,你可以参考一下写出基于CRecordset的类
      

  3.   

    DYNABIND: Illustrates Dynamic Binding of Database Columns to a Recordset
    MSDN sample
      

  4.   

    这个有一点点麻烦,我以前写过一个DBGrid,实现动态绑定,现在代码不知到哪里去了,我给你一个思路吧!你传入一个SQL语句,然后打开这个记录集    sprintf(strsql,"select * from _Nerve_Forum_Table ");
        lSet.Open(CRecordset::snapshot,strsql,CRecordset::readOnly);你可以用short filecount  = lSet.GetODBCFieldCount() 获得字段的数目
    CODBCFieldInfo& fieldinfo ;for(int i=0;i<fieldcount;i++)
    {
    lSet.GetODBCFieldInfo(i,fieldinfo); //获得字段的类型和名称,自动绑定用到的信息可以从这里获得
    }知道字段的数目,字段的类型,字段的名称,就可按照记录数提取记录的内容了。如果你懒一点,你可以用CDBVariant 类型来代替所有字段的类型。
    CDBVariant t
    int nId;
    lSet.GetFieldValue("id",t);
    ASSERT(t.m_dwType==DBVT_LONG);
    nId = t.m_lVal;
    Item.nForumId = nId; lSet.GetFieldValue("ParentId",t);
    ASSERT(t.m_dwType==DBVT_LONG);
    nId = t.m_lVal;
    Item.nParentId = nId;
      

  5.   

    TangDL:
    数据库中其实各个字段的绑定系可以用代码进行,仲记唔记得记录结果集中的各个对象用法?
    其实只要你熟悉结果集的对象,此问题就话甘快搞掂。
    编程不要依靠人地的代码,世上最好的代码仲系要靠自己我自己都曾经系呢个问题上搞了几个礼拜,希望你认真的去睇吓个结果集的对象用法。广州的wealth
      

  6.   

    To:caigzhi(caigzhi)
        “胡说”一词不知何解,这儿这么多高手,对“OLEDB就是建立在ADO的基础之上的”应有正确的理解吧!ADO我用了3年了,只是这次想换个方式。谢谢masterz、Tasehouny、wealth等,我将尽快尝试,一有结果,马上给分
      

  7.   

    CDatabase db;
    CRecordSet rt(&db);db.Open();
    CRecordSet.Open( UINT nOpenType = AFX_DB_USE_DEFAULT_TYPE, LPCTSTR lpszSQL = NULL, DWORD dwOptions = none );lpszSQL A string pointer containing one of the following: 1A NULL pointer.
    2The name of a table.
    3An SQL SELECT statement (optionally with an SQL WHERE or ORDER BY clause). 
    4A CALL statement specifying the name of a predefined query (stored procedure). Be careful that you do not insert whitespace between the curly brace and the CALL keyword.
    For more information about this string, see the table and the discussion of ClassWizard’s role under Res