关键代码为:
m_pConnection->Open("Provider=MSDAORA.1;User ID=fq;Password=123;Data Source=test;Persist Security Info=false","fq","123",adModeUnknown);
m_pRecordset->Open("student",theApp.m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdTable);
_variant_t windy("windyhui");
_variant_t age((long)8);
m_pRecordset->AddNew();
m_pRs->PutCollect("name",windy);
m_pRs->PutCollect("age",age);
m_pRs->Update();
在运行到AddNew()时出现异常,这是为什么?
m_pConnection->Open("Provider=MSDAORA.1;User ID=fq;Password=123;Data Source=test;Persist Security Info=false","fq","123",adModeUnknown);
m_pRecordset->Open("student",theApp.m_pConnection.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdTable);
_variant_t windy("windyhui");
_variant_t age((long)8);
m_pRecordset->AddNew();
m_pRs->PutCollect("name",windy);
m_pRs->PutCollect("age",age);
m_pRs->Update();
在运行到AddNew()时出现异常,这是为什么?
#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")
int main(int argc, char* argv[])
{
printf("Use ADO to open Oracle!\n");
CoInitialize(NULL);
try
{
_ConnectionPtr pConn("ADODB.Connection");
_RecordsetPtr pRst("ADODB.Recordset");
pConn->Open("Provider=OraOLEDB.Oracle;Data Source=workdb;User Id=Onega;Password=sa;"
,"","",adConnectUnspecified);
pRst->Open(
"student",
_variant_t((IDispatch *) pConn, true),
adOpenStatic,
adLockOptimistic,
adCmdTable);
pRst->AddNew();
_variant_t windy("windyhui");
_variant_t age((long)8);
pRst->Fields->Item["name"]->Value =windy;
pRst->Fields->Item["age"]->Value = age;
pRst->Update();
pRst->Close();
pConn->Close();
}
catch (_com_error &e)
{
printf("Description = '%s'\n", (char*) e.Description());
}
::CoUninitialize();
printf("program end.\n");
return 0;
}
CATCH
看一下错,也好能处理它免得把程序搞崩溃
客户端我装了
我遇到的问题是能读,但是AddNew(),和Delete时就会异常,请是是不是还是进行什么设置或者是连接和打开记录集时的参数不对,还是ORACLE的权限问题?希望大虾们能帮助解决!!
如果还有错,看看出错信息是什么。
PutCollect的用法不太常见,或许不是这么用的
不要设为AdLockReadOnly(这是默认值)
设成
AdLockPessimistic
AdLockOptimistic
或其他
怎么早没想到,
谢谢大家了!
结贴!