为什么Excel插入数据就报错?我是这样写的
::CoInitialize(NULL);
_ConnectionPtr con = NULL;
con.CreateInstance(__uuidof(Connection));
con->CursorLocation = adUseClient;
con->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\1.xls;Extended Properties=\"Excel 8.0;READONLY=FALSE;HDR=Yes;IMEX=1\";", _bstr_t(""), _bstr_t("") ,adConnectUnspecified);
_RecordsetPtr pRecord;
pRecord.CreateInstance (__uuidof(Recordset));
pRecord->CursorLocation = adUseClient;
pRecord->Open(_variant_t("INSERT INTO [Sheet28$] (索引号) VALUES ('徐景周')"), con.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText );
谢谢:)

解决方案 »

  1.   

    连接正确??
    捕捉异常
    察看_com_error的description()
      

  2.   

    try
    {
    ::CoInitialize(NULL);
    //初始端口
    _ConnectionPtr con = NULL;
    con.CreateInstance(__uuidof(Connection));
    con->CursorLocation = adUseClient;
    con->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\1.xls;Extended Properties=\"Excel 8.0;READONLY=FALSE;HDR=Yes;IMEX=1\";", _bstr_t(""), _bstr_t("") ,adConnectUnspecified);
    //con->Open("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=e:\\1.xls;Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"", _bstr_t(""), _bstr_t("") ,adConnectUnspecified);
    _RecordsetPtr pRecord;
    pRecord.CreateInstance (__uuidof(Recordset));
    pRecord->CursorLocation = adUseClient;
    pRecord->Open(_variant_t("INSERT INTO [Sheet28$] (索引号) VALUES ('徐景周')"), con.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText );
    }
    catch(_com_error &e)
    {
        AfxMessageBox(e.ErrorMessage());
    }连接是正常没有错报错如下:
    Unspecified Error
      

  3.   

    提示:Operation Must Use an Updateable Query
    好像是只读的原因
    在连接我写READONLY=FALSE;是对的啊
    为什么还在报错
      

  4.   

    不要用pRecord->Open去插数据.. 按下面方法做:
    con->Execute("insert into [Sheet28$] values('徐景周')",&RecordsAffected,adCmdText);
      

  5.   

    tabby,看到你说过ado操作excel不支持删除?
    这样的话,只能select * into 新表 from 旧表 where 其他所有记录 
    删除旧表,重命名新表或者再次select into了
      

  6.   

    提示:Operation Must Use an Updateable Query 
    好像是只读的原因 
    在连接我写READONLY=FALSE;是对的啊 
    为什么还在报错 
      

  7.   

    //连接Excel数据库,注意IMEX=1时不能插入与更新~~~~~~~~~~去掉它~~~~~~~~~~~~~~
      

  8.   

    我是这样删除数据
        ::CoInitialize(NULL);
        _ConnectionPtr con = NULL;
        con.CreateInstance(__uuidof(Connection));
        con->CursorLocation = adUseClient;
        con->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\1.xls;Extended Properties=\"Excel 8.0;READONLY=FALSE;HDR=Yes\";", _bstr_t(""), _bstr_t("") ,adConnectUnspecified);
        _RecordsetPtr pRecord;
        pRecord.CreateInstance (__uuidof(Recordset));
        pRecord->CursorLocation = adUseClient;
        LPCTSTR lpszSql=_T("Delete from [Sheet28$] where  索引号='123456789'");
        pRecord->Open(_variant_t(lpszSql), con.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText );
    报错如下:
    Deleting data in a linked table is not supported by this ISAM.
    谢谢了:)