Article ID: 194207
Article Last Modified on 12/30/2005
BEGIN_ACCESSOR_MAP(CProductsAccessor, 2) // Pass number of accessors
BEGIN_ACCESSOR(0, true) // true = an auto accessor
COLUMN_ENTRY(2, m_ProductName)
COLUMN_ENTRY(3, m_UnitPrice)
COLUMN_ENTRY(4, m_UnitsInStock)
COLUMN_ENTRY(5, m_UnitsOnOrder)
COLUMN_ENTRY(6, m_ReorderLevel)
END_ACCESSOR()
BEGIN_ACCESSOR(1, false) // false = not an autoaccessor
COLUMN_ENTRY(1, m_ProductID)
END_ACCESSOR()
END_ACCESSOR_MAP()
CProducts rs; rs.Open(); rs.ClearRecord(); strcpy(rs.ProductName,"New product name"); rs.UnitPrice = 10; rs.UnitsInStock = 0; rs.UnitsOnOrder = 100; rs.ReorderLevel = 25; rs.Insert();
rs.MoveNext(); //Move to next record retrieving values for auto accessor rs.GetData(1); //Retrieve values for accessor 1When changing data via SetData(), the accessor containing the columns you want updated (that is, not the autoincrement column) should be specified; otherwise, SetData() will loop though each accessor, including the accessor that contains the autonumber column.
rs.UnitsInStock--; // Decrement units in stock rs.SetData(0); // Update columns in accessor 0NOTE: Jet 4.0 provider will not have this limitation. To use autoincrement columns with it, you need to use COLUMN_ENTRY_STATUS(1, m_id, m_id_status) and set rs.m_id_status = DBSTATUS_S_IGNORE; before calling Insert().
Additional query words: identity
Keywords: kbhowto kbprovider kbconsumer kbdatabase kbjet KB194207