Writing a record to a property database consists of specifying the data types, property identifiers, and data values for each of the properties in the record, and then calling CeWriteRecordProps to write the record. Records can have varying numbers of properties, and new properties can be added to existing records. Listing 4.7 opens the database created in the previous sections and writes three records.
Listing 4.7 Writes a record
void WriteDBRecord(HANDLE hDB, LPTSTR lpCompanyName, long lpCompanyID, LPTSTR lpCompanyTel) { CEPROPVAL propval[4]; CEOID ceoidRec; propval[0].propid = propCompany; propval[0].val.lpwstr = lpCompanyName; propval[1].propid = propCompanyID; propval[1].val.lVal = lpCompanyID; propval[2].propid = propCompanyTel; propval[2].val.lpwstr = lpCompanyTel; ceoidRec = CeWriteRecordProps(hDB, 0, // write new record 3, // number of properties propval); if(ceoidRec == 0) cout _T("Record write failed") endl; else cout _T("Record written") endl; } void Listing4_7() { HANDLE hDB = Listing4_4(); // open database if(hDB != INVALID_HANDLE_VALUE) { WriteDBRecord(hDB, _T("Company 1"), 1, _T("998-12311")); WriteDBRecord(hDB, _T("Company 2"), 2, _T("998-12312")); WriteDBRecord(hDB, _T("Company 3"), 3, _T("998-12313")); Listing4_5(hDB); // close database } }
Just like files, folders, and databases, each record has a unique object identifier, and the object identifier is returned for the new record when CeWriteRecordProps is called.
Table 4.11. CeWriteRecordProps Writes a record's properties
CeWriteRecordProps | |
HANDLE hDbase | Database handle to write properties to |
CEOID oidRecord | Record object identifier to update, or 0 to create new record |
WORD cPropID | Number of properties to write |
CEPROPVAL * rgPropVal | CPROPVAL array specifying the property identifier, data types, and values for the properties |
CEOID Return Value | Returns object identifier for record, or 0 for failure |