CString strMain = "SELECT ID, WorkshopName, WorkshopId , TimeExtend ,Recorder , RecordTime FROM Prod_WorkTimeExtend ";
//打开结果集
updRecordset->Open(_bstr_t(strMain),
   _variant_t(DISP_E_PARAMNOTFOUND, VT_ERROR),
   adOpenStatic,
   adLockBatchOptimistic,
   adCmdText);
//修改属性值                       
FieldPtr pField2 = pRecordset->GetFields()->GetItem(CComVariant(i));
pField2->GetProperties()->GetItem(CComVariant(j))->PutValue(val1);
//出现错误
"Operation is not allowed in this context."

解决方案 »

  1.   

    ado没怎么用过,我估计你现在打开的readonly的游标,可能是adOpenStatic这个参数的原因,看看还有其它什么参数? 估计还有dynamic的,呵呵
      

  2.   

    adOpenUnspecified = -1,
        adOpenForwardOnly = 0,
        adOpenKeyset = 1,
        adOpenDynamic = 2,
        adOpenStatic = 3
    五种游标都试用过,不行,各位是否使用过这种用法,请支招!
      

  3.   

    另外两个参数:
    adLockBatchOptimistic:打开recordset时所用的锁,我用的是允许批更新的锁。
    adCmdText:指示数据源即strMain中是存储过程、表还是sql语句,我选择sql语句。另外,我询问了oracle公司,他们给出的回答现共享给各位:
    使用oracle的过程中ref cursor返回的recordset是不可以修改,即使是recordset的field属性值可以修改(断开连接),也会出错的,但是sql server下的存储过程就可以。
    “we never intend to update the database via the recordset.  In fact it is understandably impossible to do so since there is no known key or  rowid available to identify how to update any given row in the database.With Microsoft's provider we can achieve this  since it allows field values to be set (even if it does not let the recordset  to be updated).  With Oracle's provider we cannot since it does not allow a  field to be set.  This forces us to abandon the procedure call and lose the  benefits of static SQL and re-using the cursor in the session cursor cache.   This hurts our scalability.  As you say, the recordset should not and cannot  be used to update the database.  I am not wanting that.  But I am wanting to use the recordset for something it is very good at - communicating information between many client-side components that utilize the recordset interface.”
    感谢“影子”及各位,现结贴!