1. Using CRecordset::AddNew() and CRecordset::Edit() with IDENTITY fields
Hey all,
I've noticed some strange behavior in the CRecordset-derived objects which
are based on tables with IDENTITY (or Autonumber) fields. The
documentation for the CRecordset says that you should use AddNew()/Update()
and Edit()/Update() function calls to insert new records and edit existing
records in a recordset. The problem is that when doing this on a table
which has a IDENTITY field, an exception is caused which states that you
are trying to modify an IDENTITY field, or something like that.
How can the CRecordset functions AddNew(), Edit(), and Update(), work at
all in databases where IDENTITY fields are quite common in table
definitions (as is the case for me)? As it is, I've resorted to using the
ExecuteSQL() member function of the CDatabase object which was used to
construct the CRecordset-derived object. It seems, however, that the
CRecordset functions mentioned above should be sensitive to IDENTITY
fields, and not make them part of an INSERT or UPDATE statement.
Does anyone know if there is a proper way to deal with IDENTITY fields
using the CRecordset functions mentioned? (Excluding them from the bound
fields for the CRecordset-derived class is *NOT* an option as they are used
as indices into other tables, so knowing the value of the identity field is
required.)
I've seen mention of 'parameter' fields in the DoFieldExchange
documentation, but class wizard sure doesn't bother making identity fields
into parameter members of the recordset. Is using the parameter fields the
answer to this problem? If so, is this a manual change that needs to be
made to the recordset class after class wizard's done with it, or can class
wizard be made to recognize identity fields and make them parameter fields
in the class?
--
Loren James Erickson
http://www.ami-med.com/
2. Row Numbers
3. Timeout expired, [Microsoft OLE DB Provider for SQL Server]
4. VC5 to VC6 CRecordSet ODBC access problem across .DLLs
5. SQL 6 and Dropping / Changing Columns
6. CRecordset problem when table is big.
7. No work was done error.
8. CRecordset::Update problem
9. Problem with Access 2000 and CDatabase/CRecordset
10. CRecordset insertion Problem
11. CRecordset->Delete() Problem
12. Problem updating SQL Server via ODBC/CRecordset