Adding an item into a custom table

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The following code sample shows how a new data item can be added to an existing custom table.

 

[C#]

 

using CMS.CMSHelper;

using CMS.SettingsProvider;

using CMS.SiteProvider;

using CMS.DataEngine;

 

...

 

        string customTableClassName = "customtable.SampleTable";

 

        // Get data class using custom table name

        DataClassInfo customTableClassInfo = DataClassInfoProvider.GetDataClass(customTableClassName);

        if (customTableClassInfo == null)

        {

            throw new Exception("Given custom table does not exist.");

        }

 

      // Initialize custom table item provider with current user info and general connection

      CustomTableItemProvider ctiProvider = new CustomTableItemProvider(CMSContext.CurrentUser, ConnectionHelper.GetConnection());

 

        // Create new custom table item for given class of custom table

        CustomTableItem item = new CustomTableItem(customTableClassInfo.ClassName, ctiProvider);

 

        // Set value of a custom table item field

        item.SetValue("ItemText""Sample item text");

 

        // Insert the item

        item.Insert();

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_adding_an_item_into_a_custom_table.htm