Update and Add Data

Check If Record Already Exists Before Saving Data

This customization shows how to verify if a record already exists when inserting a new record.
Select a record control
Table Name
Select a table to insert record
Primary Key
Select the primary key in the table
Primary Key Control
Select the primary key control in the table
Applies to
RecordControl class
/// This sub is called when a record is getting saved. Call base.SaveData()
/// only if duplicate record is not present in the database.
public override void SaveData()
    string whereStr = ${${Table Name}ClassName}.${Primary Key}.UniqueName + " = '" + this.${Primary Key Control}.Text + "'";

    // Check if record already exists before saving.
    ${${Table Name}RecordClassName}  rec = ${${Table Name}ClassName}.GetRecord(whereStr);
    if (rec != null)
        // If record exists, do not save the record       
        // Save the record if it does not exists

Terms of Service Privacy Statement