_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());
}
_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());
}
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方法吗?
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.
请大家帮忙看看!