Update a record
- Last UpdatedApr 08, 2026
- 1 minute read
This scenario guides you through the steps required to update an analog record in the RealTime database (RTDB).
To identify the code associated with each step, see the code comments in the Example code section.
To update a record
- Open the Program.cs file from the created project.
- Open the RTDB.
- Access the analog table.
- Lock the analog table for reading.
- Lock the record for writing.
- Write the description field by using one of the following methods:
- Using the record number, if known.
using (IRealTimeRecord record = new RealTimeRecord(table)) { record.BindRecordNumber(28); record.Lock(recordLockRequest.SAFE_WRITE); record.WriteField<String>("description", "AnalogPoint_1 desc updated"); } - Getting the record by name.
var nameField = new RealTimeStringField(table, "name"); using (IRealTimeRecord record = table.FindRecord(nameField, "AnalogPoint_1")) { record.Lock(recordLockRequest.SAFE_WRITE); record.WriteField<String>("description", "AnalogPoint_1 desc updated"); }
- Using the record number, if known.
- Unlock the record.
- Unlock the analog table.
Example code
IRealTimeDatabase database = new RealTimeDatabase();
try
{
// Open the RTDB.
if (!database.IsOpen())
{
database.Open();
}
// Access the analog table.
using (IRealTimeTable table = new RealTimeTable("analog"))
{
ITableLockRequestType tableLockRequest = new TableLockRequestType();
IRecordLockRequestType recordLockRequest = new RecordLockRequestType();
// Lock the analog table for reading.
table.Lock(tableLockRequest.SAFE_READ);
// Write the description field.
var nameField = new RealTimeStringField(table, "name");
using (IRealTimeRecord record = table.FindRecord(nameField, "AnalogPoint_1"))
{
// Lock the record for writing.
record.Lock(recordLockRequest.SAFE_WRITE);
record.WriteField<String>("description", "AnalogPoint_1 desc updated");
} // Leaving scope releases the record lock.
} // Leaving scope releases the analog table lock.
}
catch (Exception ex)
{
Console.WriteLine(quot;Error updating a record: {ex.Message}");
}