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();
}
}