当我用CDatabase连接上数据库,并且用CRecordSet打开数据库后,怎样进行对数据库进行删除、添加、修改等?
我看了一下MSDN好像没有相关的函数。
还有使用ODBC MFC进行数据库编程,在类向导中没有选中对数据库的支持,之后如果要进行数据库方面的操作,如何修改,要什么头文件?

解决方案 »

  1.   

    1.
    Recordset Update Operations
    AddNew 
     Prepares for adding a new record. Call Update to complete the addition. 
     
    CancelUpdate 
     Cancels any pending updates due to an AddNew or Edit operation. 
     
    Delete 
     Deletes the current record from the recordset. You must explicitly scroll to another record after the deletion. 
     
    Edit 
     Prepares for changes to the current record. Call Update to complete the edit. 
     
    Update 
     Completes an AddNew or Edit operation by saving the new or edited data on the data source. 2.不同的连接字符串连接不同的数据库.
      

  2.   

    建议楼主用两个小时专研一下SQL语言,保证数据库的基本操作完全可以应付,可以用数据库类的Excute函数执行对数据库的操作
      

  3.   

    CRecordset对象只是从你的数据库中根据你不同的SQL语句获取的一个记录集;在该对象上的操作,只是对记录集的操作,不会影响原来数据库中的数据;初试化操作://定义一个CDatabase变量用于和数据库简历连接,一个CRecordset变量,用于保存记录集;
    CDatabase m_db;
    CRecordset m_recordset;
    //使用m_db与数据源建立连接;
    m_db.open(····)
    //绑定数据源与记录集
    m_recordset.m_pDatabase = &m_db; 
    数据库操作:
    //例如要查询信息
    m_recordset.Open(CRecordset::dynaset,"select* from userInfo")
    //如果要操作数据库中的信息
    CString str = "SQL 语句";
    m_db.ExecuteSQL(str);
      

  4.   

          有的时候,用MFC的ODBC封装类还是蛮方便的.