Answers for "Kentico 9 - Updating the data records of a custom table"

C#
0

Kentico 9 - Updating the data records of a custom table

// Prepares the code name (class name) of the custom table
string customTableClassName = "customtable.sampletable";

// Gets the custom table
DataClassInfo customTable = DataClassInfoProvider.GetDataClassInfo(customTableClassName);
if (customTable != null)
{
    // Gets all data records from the custom table whose 'ItemText' field value starts with 'New text'
    var customTableData = CustomTableItemProvider.GetItems(customTableClassName)
                                                        .WhereStartsWith("ItemText", "New text");

    // Loops through individual custom table records
    foreach (CustomTableItem item in customTableData)
    {
        // Gets the text value from the data record's 'ItemText' field
        string itemText = ValidationHelper.GetString(item.GetValue("ItemText"), "");

        // Sets a new 'ItemText' value based on the old one
        item.SetValue("ItemText", itemText.ToLowerCSafe());

        // Saves the changes to the database
        item.Update();
    }
}
Posted by: Guest on June-25-2021

Code answers related to "Kentico 9 - Updating the data records of a custom table"

C# Answers by Framework

Browse Popular Code Answers by Language