我在程序中设定了maxrecords为10,打开recordset时已有10条记录,此时在addnew,运行时会出错

strSQL.Format(_T("Select * From %s"),strTableName);

m_pCommand->ActiveConnection = m_pConnection ;
if(!m_pCommand->ActiveConnection->State)
return;
m_pCommand->CommandText = _bstr_t(strSQL);

if (m_pRecordset->State)
{
m_pRecordset->Close();
}

m_pRecordset->MaxRecords = 10;
m_pRecordset->CursorLocation = adUseClient;
m_pRecordset->Open ((IDispatch *) m_pCommand, vtMissing, adOpenDynamic,adLockOptimistic,adCmdText );
... m_pRecordset->AddNew();  m_pRecordset->put_Collect(_variant_t("ID"),_variant_t(strID));
   m_pRecordset->Update();

解决方案 »

  1.   

    如果你限定了Maxrecords,但select 的时候只返回了少于10条
    那么你可以Addnew,只是总数最多添加到10条如果select返回了10条或者多余10条,但是maxrecords限定了,recordset里面只有10条记录,那么addnew出错你可以select top 9 * from table1试验一下
      

  2.   

    strSQL.Format(_T("Select * From '%s'"),strTableName);
      

  3.   

    赞同vieri_ch的观点,在记录集未满的情况下,才可以addnew。
    我想在记录集满了的情况下加入记录,那是不怀好意啊,程序不跟我客气。