我定义的对象入下:
CDataSource ds;
CSession ss;
CCommand<CDynamicAccessor> rs;我用rs.open(...)成功打开了数据库,并设置了DBPROP_UPDATABILITY
可我不知道怎么插入数据, 我调用rs.Insert()返回S_OK,但调用rs.Update时就出错,这是为什么??

解决方案 »

  1.   

    ........终于有人回了...我是在VS.NET下写的,你帮我看一下吧,谢谢!! :) CDataSource ds;
    CSession ss;
    CCommand<CDynamicAccessor> rs; CoInitialize(NULL);
    USES_CONVERSION; ds.Open();
    BSTR buff;
    ds.GetInitializationString(&buff, true); cout<<OLE2T(buff)<<endl;;
    SysFreeString(buff);
    ss.Open(ds); CDBPropSet* DBPropSet = new CDBPropSet(DBPROPSET_ROWSET);
    DBPropSet->AddProperty(DBPROP_IRowsetUpdate, true);
    DBPropSet->AddProperty(DBPROP_UPDATABILITY,
    DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_DELETE | DBPROPVAL_UP_INSERT);
    DBPropSet->AddProperty(DBPROP_CANSCROLLBACKWARDS, true);
    DBPropSet->AddProperty(DBPROP_CANFETCHBACKWARDS, true); rs.Open(ss, "SELECT 姓名 FROM oletest", (DBPROPSET*)DBPropSet); for(DBORDINAL col = 1; col <= rs.GetColumnCount(); col++)
    {
    LPTSTR szBuff = OLE2T(rs.GetColumnName( col ));
    cout<<szBuff<<'\t';
    }
    cout<<endl; HRESULT hr = rs.MoveNext();
    while(SUCCEEDED(hr) && hr != DB_S_ENDOFROWSET)
    {
    DBSTATUS  DBStatus;
    DBTYPE  DBType; rs.GetStatus( 1, &DBStatus);
    rs.GetColumnType(1, &DBType); if(FAILED(DBStatus))
    cout<<"FAILED";
    else if( DBStatus == DBSTATUS_S_ISNULL )
    cout<<"<<NULL>>";
    else if( DBType == DBTYPE_WSTR || DBType == DBTYPE_STR)
    {
    LPWSTR buff = (LPWSTR)rs.GetValue(1);
    CString pszData = CString(buff);
    cout<<pszData; }
    cout<<endl; hr = rs.MoveNext();
    }
    LPWSTR pwszName = (LPWSTR)rs.GetValue(1);
    wcscpy(pwszName, L"uu");
    //rs.SetLength(1,2);
    rs.SetStatus(1, DBSTATUS_S_OK);
    rs.Insert();
    rs.Update();
    ///////////在这里就出错了,下面的就不用看了/////////////
    rs.MoveFirst(); LPWSTR pwszData = (LPWSTR)rs.GetValue(1);
    wcscpy(pwszData, L"hhh");
    DBCOUNTITEM rt = 0;
    rs.SetData();
    rs.Update();
    cout<<rt<<endl; rs.Close();
    ss.Close();
    ds.Close();
    CoUninitialize();帮帮我啊...谢谢
      

  2.   

    照上面的代码,调用rs.Update()的错误是DB_E_ROWSNOTRELEASED(列没有释放)
    如果在它的前面加了rs.ReleaseRows() rs.Update()的错误是DB_E_ERRORSOCCURED(发生错误)...晕啊!!!~~~ 有没有人知道这个怎么弄啊?