LockEdits Property Example (VC++)

This example opens a dynaset-type Recordset and sets its LockEdits property to False. This enables optimistic locking so other users can change the database records at any time. Your application triggers a trappable error if the data changes before you use the Update method.

CdbDBEngine      DBEng;
CdbDatabase      dbsNorthwind;
CdbRecordset   rstCustomers;

dbsNorthwind = DBEng.OpenDatabase(_T("Northwind.mdb"));
rstCustomers = dbsNorthwind.OpenRecordset(_T("Customers"),
                     dbOpenDynaset);
rstCustomers.SetLockEdits(-1);
try
{
   rstCustomers.Edit();
}
catch (CdbException e)
{
   if (DBEng.Errors[0L].GetNumber() == 3197)
      printf(_T("data changed\n"));
   else
      printf(_T("some other error\n"));
}

rstCustomers.CancelUpdate();
rstCustomers.Close();
dbsNorthwind.Close();