ADOConn m_AdoConn;\\一个SQL的类
m_AdoConn.OnInitADOConn();\\连接到SQL数据库
_bstr_t sql;
sql = "select * from employees";
_RecordsetPtr m_pRecordset;
m_pRecordset=m_AdoConn.GetRecordSet(sql);\\获取数据集
CString sex;
m_combo.GetLBText(m_combo.GetCurSel(),sex);
try
{
m_pRecordset->AddNew();//添加新行
m_pRecordset->PutCollect("编号",(_bstr_t)m_id);
m_pRecordset->PutCollect("姓名",(_bstr_t)m_name);
m_pRecordset->PutCollect("性别",(_bstr_t)sex);
m_AdoConn.ExitConnect();\\关闭数据库连接,总是出现错误。代码如下。
}
catch(...)
{
MessageBox("操作失败");
return;
}
MessageBox("保存成功");
**********************************************************************************************
void ExitConnect()
{
     if(m_pRecordset != null)
        m_pRecordset->Close();
     m_pConnection->Close();
}
各位给看看是那的事呀,谢谢

解决方案 »

  1.   

    异常捕获换成这样
    try
    {
    //你的ADO代码
    }
    catch (_com_error& e)
    {
    AfxMessageBox(e.Description());
    }
      

  2.   

    还是不行,用
    try
    {
    //你的ADO代码
    }
    catch (_com_error& e)
    {
    AfxMessageBox(e.Description());
    }
    后就显示保存成功,但是在SQL查询软件中查不到,存不进去。
      

  3.   

    什么数据库,是Access的话打开记录集的后面三个参数换成这样试试。
         m_pRecordset->Open("SELECT * FROM DemoTable",                // 查询DemoTable表中所有字段  
                             theApp.m_pConnection.GetInterfacePtr(),  // 获取库接库的IDispatch指针  
                             adOpenDynamic,  
                             adLockOptimistic,  
                             adCmdText
    )
      

  4.   

    你没有   update 吧