Using DAO in ODBC Mode -- Snapshots and Dynasets

You've already heard that DAO goes far beyond ODBC, but let's take things one step at a time. We'll start with DAO snapshots and dynasets, which behave pretty much the same way in DAO as they do in ODBC. You can use snapshots and dynasets with ODBC data sources, ISAM-type files, and Access tables. You write programs using the MFC library classes CDaoDatabase and CDaoRecordset, which are very similar to the ODBC classes CDatabase and CRecordset. There are a few notable differences, however:

  • The CDaoRecordset::GetRecordCount function works differently from the CRecordset::GetRecordCount function. For attached tables and ODBC data sources, CDaoRecordset::GetRecordCount always returns -1. For Access tables and ISAM-type files, it returns the number of records actually read, which is the final count for the recordset only if you have moved to the last record. Unfortunately, DAO has no equivalent for the ODBC CRecordset::GetStatus function, so you can't test a DAO recordset to find out whether the record count is indeed final.

  • With DAO, you can get and set the absolute position of the current record in a dynaset or a snapshot, you can get and set a percent position, you can find a record containing a matching string, and you can use bookmarks to mark records for later retrieval.

  • DAO makes it easy to get and set column values without binding. Because values are passed as VARIANTs, you can build dynamic applications that adjust to the database schema at runtime.

One important thing to remember about snapshot recordsets is that the record count never changes. With dynasets, the record count changes only if you delete or add records in the dynaset. If another user deletes a record, that record is marked as deleted in your dynaset; if another user adds a record, you don't see that record in your dynaset. If you add a record to a dynaset, that record is added at the end of the dynaset, regardless of the sort order.



Programming Microsoft Visual C++
Programming Microsoft Visual C++
ISBN: 1572318570
EAN: 2147483647
Year: 1997
Pages: 332

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net