To update an existing record, you need to perform the following actions:
// update the first record
ARecord.First();
// change the first field
ARecord.SetFieldAsString(0, "Joe Smith");
// write the record
try
{
ARecord.Write();
}
catch (CTException err)
{
Console.Write("Update record failed with error {0}\n", err.GetErrorCode());
}
A record is updated when the new record flag is cleared and the edited record flag is set. The new record flag is cleared when a record is read from disk and it indicates that this is an existing record.
If you read a record from disk, and without updating the record data, call CTRecord.Write(), no data record is written to disk, since the edited record flag is cleared.
A record update can be forced by setting the record edited flag with a call to CTRecord.SetEdited() method.
// force update of first record
ARecord.First();
// set the edited flag
ARecord.SetEdited(true);
// write the record
try
{
ARecord.Write();
}
catch (CTException err)
{
Console.Write("Update record failed with error {0}\n", err.GetErrorCode());
}
A record can be duplicated by reading it from disk, setting the edited record flag by calling CTRecord.SetEdited() setting the new record flag by calling CTRecord.SetNew(), and calling CTRecord.Write() to write it to disk. Please note that a record can only be duplicated if the table has no indexes with unique keys.
// duplicate the first record
ARecord.First();
// set the edited flag
ARecord.SetEdited(true);
// set the new record flag
ARecord.SetNew(true);
// write the record
try
{
ARecord.Write();
}
catch (CTException err)
{
Console.Write("Write record failed with error {0}\n", err.GetErrorCode());
}