CString str1=_T("说明");
CString str2=_T("说明");
CString str3=_T("说明");
CString str4=_T("说明");
CString str5=_T("说明");
CString str6=_T("说明");
        _variant_t recodsaffected;
CString strSQL;
strSQL.Format("INSERT INTO yinpian6(worker6,state6,suntitle6,benshu6,jihao6,time6) VALUES('%s','%s','%s','%s','%s','%s')",str1,str2,str3,str4,str5,str6);
m_pConnection->Execute((_bstr_t)strSQL,&recodsaffected,adCmdText);
yinpian6(worker6,state6,suntitle6,benshu6,jihao6,time6) VALUES('%s','%s','%s','%s','%s','%s')",str1,str2,str3,str4,str5,str6);
  这个是我在D盘的建立的一个ACCESS表格的字段worker6,state6,suntitle6,benshu6,jihao6,time6,都是文本型,不知道问什么失败啊
运行就是rutime error
恳请大侠帮忙啊 MessageBox("恭喜你加入信息");

解决方案 »

  1.   

    try{ //sql操作}
    catch(_com_error e)
    {
    CString strComError;
           strComError.Format("错误编号: %08lx\n错误信息: %s\n错误源: %s\n错误描述: %s",
           e.Error(), // 错误编号
           e.ErrorMessage(), // 错误信息
           (LPCSTR) e.Source(), // 错误源
           (LPCSTR) e.Description()); // 错误描述
           ::MessageBox(NULL,strComError,"错误",MB_ICONEXCLAMATION);
    }然后看看
      

  2.   

    sql语句书写错误之类的情况很容易出现。
      

  3.   

    1.可以get error
    2.也可以自己单步跟踪看看是哪句出问题
    3.注意你的ACCESS文件 是不是已经打开 lock了  自己打开一下那个文件 再正常关闭
      

  4.   

    Debug调试一下,看看sql语句字符串是否正确,哪个函数失败返回???
      

  5.   

    说的是在对应的名称或者项目中没有找到项目
    错误编号:800a0cc1;
    错误源,ADODB.Recordset
    错误描述在对应的名称或者序数的集合中没有找到项目
      

  6.   

    UpdateData();
    CString str1=_T("说明");
    CString str2=_T("说明");
    CString str3=_T("说明");
    CString str4=_T("说明");
    CString str5=_T("说明");
    CString str6=_T("说明"); char* str8="hello";
    _bstr_t sql;
    sql = "select * from yinpian6";
    m_pRecordset.CreateInstance(__uuidof(Recordset));
    m_pRecordset->Open(sql,m_pConnection.GetInterfacePtr(),\
    adOpenDynamic,adLockOptimistic,adCmdText);
    // m_pRecordset->Open(sql,_variant_t((IDispatch*)m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText); 
    // m_pRecordset->Open("select * from yinpian6",_variant_t((IDispatch*)m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText); 
    m_pRecordset->MoveLast();
    try
    {
    m_pRecordset->AddNew(); //添加新行
    m_pRecordset->PutCollect("worker6",_variant_t("hello"));
    // m_pRecordset->PutCollect()
    /* m_pRecordset->PutCollect("state6",_bstr_t("hello"));
    m_pRecordset->PutCollect("suntitle6",_bstr_t("hello"));
    m_pRecordset->PutCollect("benshu6",_bstr_t("hello")); m_pRecordset->PutCollect("jihao6",_bstr_t("hello"));
    m_pRecordset->PutCollect("time6",_bstr_t("hello"));
    */ m_pRecordset->Update(); //更新数据表
    ExitConnect();
    }
    catch(_com_error e)
    {
    // MessageBox("操作失败");
    CString strComError;
    strComError.Format("错误编号: %08lx\n错误信息: %s\n错误源: %s\n错误描述: %s",
    e.Error(), // 错误编号
    e.ErrorMessage(), // 错误信息
    (LPCSTR) e.Source(), // 错误源
    (LPCSTR) e.Description()); // 错误描述
    ::MessageBox(NULL,strComError,"错误",MB_ICONEXCLAMATION);// return;
    }
    MessageBox("添加成功");其中就是红色一行就开始错误了。不知道怎么改啊。
    刚学,大侠指点指点啊!!!
      

  7.   

    yinpian6这个表中是否有worker6这个字段,没有的话添加。
    可以打开表手动保持一致。
    也可以用create来保持一致。