关键代码为:
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()时出现异常,这是为什么?

解决方案 »

  1.   

    #include "stdafx.h"
    #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;
    }
      

  2.   

    TRY
    CATCH
    看一下错,也好能处理它免得把程序搞崩溃
      

  3.   

    多谢各位的指点!
    客户端我装了
    我遇到的问题是能读,但是AddNew(),和Delete时就会异常,请是是不是还是进行什么设置或者是连接和打开记录集时的参数不对,还是ORACLE的权限问题?希望大虾们能帮助解决!!
      

  4.   

    你用我的代码试试呢,那是能够添加记录的,你改一下用户名,密码
    如果还有错,看看出错信息是什么。
    PutCollect的用法不太常见,或许不是这么用的
      

  5.   

    我用Recordset的Support方法检测了一下,不支持AddNew()这是为什么?
      

  6.   

    这和你的记录集打开方式有关
    不要设为AdLockReadOnly(这是默认值)
    设成
    AdLockPessimistic  
    AdLockOptimistic 
    或其他
      

  7.   

    是阿,你直接在里面用SQL语句就行了嘛,那种方式不好控制
      

  8.   

    原来要m_pConn->CursorLocation=adUseClient;
    怎么早没想到,
    谢谢大家了!
    结贴!