为什么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 );
谢谢:)
::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 );
谢谢:)
解决方案 »
- VC++画直线
- 在debug下程序正常 release下出现字节错位现象
- 如何实现脱离IE向HTTP站点发送POST数据,并接收返回数据
- 有消息钩子,API钩子,那有没有事件钩子?
- class CPhonesListBox:public ClistBox之后出现了问题我没找到,帮忙找找谢谢了,急呀!!!!
- 高分求助,仙人指路
- 如何排序最简?
- 有关调试工具设置的问题,请帮帮忙吧!
- 关于cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
- 关于重载OnPrint()函数——救命!!!(我不懂给分是什么意思)
- 各位大侠添加子菜单后,响应它咋办
- 【【!超级无敌霹雳!】】XML与树形控件的问题?
捕捉异常
察看_com_error的description()
{
::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
好像是只读的原因
在连接我写READONLY=FALSE;是对的啊
为什么还在报错
con->Execute("insert into [Sheet28$] values('徐景周')",&RecordsAffected,adCmdText);
这样的话,只能select * into 新表 from 旧表 where 其他所有记录
删除旧表,重命名新表或者再次select into了
好像是只读的原因
在连接我写READONLY=FALSE;是对的啊
为什么还在报错
::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.
谢谢了:)