Dynaset-Type Recordset Example (VC++)

This example creates a new dynaset-type Recordset object and opens it, appending it to the Recordsets collection in the default database. It then edits the record(s).

CdbDBEngine      dbeng;
CdbDatabase      dbsBiblio;
CdbRecordset      rstTitles;
CString         strSelect;

dbsBiblio = dbeng.OpenDatabase(_T("Biblio.mdb"));

strSelect = _T("Select * From Titles Where Title = 'Using SQL' ");
rstTitles = dbsBiblio.OpenRecordset(strSelect, dbOpenDynaset);

if (rstTitles.GetRecordCount() > 0 && rstTitles.GetUpdatable())
   {
   do
      {
      rstTitles.Edit();
      rstTitles.SetField(_T("Year Published"), COleVariant(1994L));
      rstTitles.Update();
      rstTitles.MoveNext();
      }
   while (rstTitles.GetEOF());
   } 
else
   {
   printf(_T("No such title or table not updatable"));
   }
dbsBiblio.Close();