Overwrite a record
- Last UpdatedApr 08, 2026
- 2 minute read
This scenario guides you through the steps required to overwrite a record.
For this scenario, you will need to perform the following tasks:
- Create a local memory record.
- Change field values.
- Write the created local record back to the database.
To identify the code associated with each step, see the code comments in the Example code section.
To overwrite a record
- Open the Program.cs file from the created project.
- Open the RealTime database (RTDB).
- Lock the analog table for writing.
- Find the analog record to get its pointer by name.
- Lock the analog record for reading.
- Create a local memory record (clone).
- Change the name and description of the cloned record.
- Overwrite the existing record with the new one.
- Unlock the analog record.
- Unlock the analog table.
Example code
IRealTimeDatabase database = new RealTimeDatabase();
try
{
// Open the RTDB.
if (!database.IsOpen())
{
database.Open();
}
using (IRealTimeTable table = new RealTimeTable("analog"))
{
ITableLockRequestType tableLockRequest = new TableLockRequestType();
IRecordLockRequestType recordLockRequest = new RecordLockRequestType();
// Lock the analog table for writing.
table.Lock(tableLockRequest.SAFE_WRITE);
// Find the analog record to get its pointer by name.
var nameField = new RealTimeStringField(table, "name");
using (var record = table.FindRecord(nameField, "ExtraAnalog"))
{
// Lock the analog record for reading.
record.Lock(recordLockRequest.SAFE_WRITE);
// Create a local memory record (clone).
var clonedRec = record.CloneInMemoryCopy();
// Change the name and description of the cloned record.
clonedRec.WriteField("description", "Description of cloned record");
clonedRec.WriteField("name", "ExtraAnalogCloned");
// Overwrite the existing record with the new one.
record.WriteRecord((RealTimeBaseRecord)clonedRec);
} // Leaving scope releases the analog record lock.
} // Leaving scope releases the analog table lock.
}
catch (Exception ex)
{
Console.WriteLine(quot;Error overwriting the record: {ex.Message}");
}