NoMatch Property Example (VC++)

This example changes the job title of all sales representatives in an Employees table. It creates a dynaset-type Recordset and then uses FindFirst and FindNext to locate every record satisfying the criteria for the title. It prepares each record for editing, changes the title, and saves the change with the Update method.

Cstring      strCriteria;
CdbBookmark   varSaveHere;

CdbDBEngine   DBEng;
CdbDatabase   dbsNorthwind;
CdbRecordset   rstEmployees;

strCriteria = (_T("Title = 'Sales Representative'")); 
dbsNorthwind =  DBEng.OpenDatabase(_T("Northwind.mdb"));
rstEmployees = dbsNorthwind.OpenRecordset(_T("Employees"), dbOpenDynaset); 
varSaveHere = rstEmployees.GetBookmark(); //   ' Save Bookmark.

rstEmployees.FindFirst(strCriteria); //   ' Locate first occurrence.
while (! rstEmployees.GetNoMatch())
   {
   rstEmployees.Edit();            //   ' Enable editing.
   rstEmployees.SetField(_T("Title"), 
COleVariant(_T("Account Executive"));
   rstEmployees.Update();         //   ' Save changes.
   rstEmployees.FindNext(strCriteria);   //   ' Locate next record.
   }
rstEmployees.SetBookmark(&varSaveHere);

Note In some situations, using an update query is faster.