出问题的代码段
while(!pRst->rsEOF)
{
_variant_t vColumn,vValue;
vColumn.SetString("Categorization");
vValue.SetString(writeInfo.c_str());
pRst->Update(vColumn,vValue);、//这里报错
writeInfo="";
belongAutomation=0;
belongComputer=0;
pRst->MoveNext();
}
错误类型:nhandled exception at 0x7c812afb in test.exe: Microsoft C++ exception: _com_error at memory location 0x0012f8f0..
转到文件:
inline HRESULT Recordset15::Update ( const _variant_t & Fields, const _variant_t & Values ) {
HRESULT _hr = raw_Update(Fields, Values);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _hr;
数据库连接等语句
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
char * selectsql="select ArticleId,ClassifyNum,Categorization from Article where ArticleId between 1 and 10 order by ArticleId";
pConn->ConnectionString="Provider=SQLOLEDB.1;Password=xxx;Persist Security Info=True; User ID=sa;Initial Catalog=ArticleCollection";
pConn->Open("","","",adConnectUnspecified);
pRst=pConn->Execute(selectsql,NULL,adCmdText);
就是数据类型不对吧!不能用 vValue.SetString.
我测试了下,也没问题.
vValue.SetString("465465qwer123");
string writeInfo="baby";
vValue.SetString(writeInfo.c_str());
我这样用也没有错啊!