_bstr_t source("Provider=MSDAORA;Data Source=ltk;User ID=system;Password=manager");
_bstr_t user("");
_bstr_t pwd("");
HRESULT hr;
try
{
CoInitialize(NULL);
hr=m_connection.CreateInstance(__uuidof(Connection));
m_connection->IsolationLevel=adXactUnspecified;
m_connection->put_CursorLocation(adUseClientBatch);
if(SUCCEEDED(hr))
hr=m_connection->Open(source,user,pwd,-1);
}
catch(_com_error & e)
{
MessageBox(e.ErrorMessage());
}
CString strQuery;
strQuery.Format("ltk.hiw_tp_touch");
_bstr_t query=strQuery;
_bstr_t source=m_strSource;
try
{
hr=m_recordset.CreateInstance(__uuidof(Recordset));
if(SUCCEEDED(hr))
{
m_recordset->put_CursorLocation(adUseClientBatch);
m_recordset->CursorLocation = adUseClient;
m_recordset->CursorType = adOpenStatic;
m_recordset->LockType  = adLockBatchOptimistic;
m_recordset->put_MarshalOptions(adMarshalModifiedOnly);
}
if(SUCCEEDED(hr))
if((IDispatch*)m_connection!=NULL)
hr=m_recordset->Open(query,(IDispatch*)m_connection,adOpenStatic,adLockBatchOptimistic,adCmdTable);
MessageBox("","",MB_OK);
}
catch(_com_error & e)
{
MessageBox(e.ErrorMessage());
}
try
{
m_recordset->Filter="status=0";
long num=m_recordset->GetRecordCount();
if(num==0)
{
MessageBox("wu","wujilu",MB_OKCANCEL);
}
for(int i=0;i<num;i++)
{
m_recordset->Delete(adAffectCurrent);            m_recordset->MarshalOptions=adMarshalModifiedOnly;
m_recordset->UpdateBatch(adAffectCurrent);
m_recordset->MoveNext();
varFilter.vt = VT_I2;
varFilter.iVal = adFilterAffectedRecords;
m_recordset->PutFilter(varFilter);
m_recordset->UpdateBatch(adAffectCurrent);*/
}
}
catch(_com_error & e)
{
MessageBox(e.ErrorMessage());
}

解决方案 »

  1.   

    m_pRecordset->Delete(adAffectCurrent);///删除当前记录
      

  2.   

    可能要通过adocommand对象来执行SQL语句来完成删除多条记录的功能,delete方法只能删除当前记录。
      

  3.   

    同意 zgdhj95(我来自杭州) ffish我来自大连^_^。就得用sql语句的条件删除。你代码中的删促可能不会完成,因为ado中的GetRecordSet()不是很好用,可能不会获得确切的符合条件的查询内容,如果真的希望用这个,希望先对查询结果进行MoveFirst()和MoveLast()然后再使用GetRecordSet(),再MoveFirst()。建议使用while(!xxx.IsEOF())
      

  4.   

    Delete Method
    The Delete method on a Recordset object deletes the current record or a group of records.recordSet.Delete
     
    Parameters
    AffectedRecords 
    This optional parameter specifies an AffectEnum value that determines how many records the Delete method will affect. The AffectEnum value can be one of the following constants: Enumeration Value Description 
    adAffectCurrent 1  This value deletes only the current record. 
    adAffectGroup 2  This value deletes the records that satisfy the current Filterproperty setting. You must set the Filter property to one of the valid predefined constants to use this option. 
    Res
    The Delete method is used to  the current record or a group of records in a Recordset object for deletion. If the Recordset object does not allow record deletion, an error occurs. If you are in immediate update mode, deletions occur in the database immediately. Otherwise, the records are ed for deletion from the cache and the actual deletion happens when the UpdateBatch method is called. (Use the Filter property to view the deleted records.)Retrieving field values from the deleted record generates an error. After deleting the current record, the deleted record remains current until you move to a different record. After you move away from the deleted record, it is no longer accessible.If you are in batch update mode, the CancelBatch method can be used to cancel a pending deletion or group of pending deletions.If the attempt to delete records fails because of a conflict with the underlying data (for example, a record has already been deleted by another user), the data provider returns warnings to the Errors collection but does not halt program execution. A run-time error occurs only if there are conflicts on all the requested records.
    我还想问一下,这段话不是在将delete方法吗?
      

  5.   

    m_pRecordset->Delete(AffectEnum AffectRecords) 
    AffectRecords Can be one of the following constants.
        adAffectCurrent 
    Default. Delete only the current record.
        adAffectGroup 
    Delete the records that satisfy the current Filter property setting. You must set the Filter property to one of the valid predefined constants in order to use this option.
        adAffectAll 
    Delete all records.
       adAffectAllChapters 
    Delete all chapter records.
      

  6.   

    我现在用adAffectAll但是报一个错误(-2146825069 800a0c93)
    请大家帮忙看看!
      

  7.   

    我现在用的是oracle9i数据库,我想我的数据库应该可以进行数据库多条记录的删除!