|
||
This code example shows how an existing form record can be modified.
[C#]
using CMS.FormEngine; using CMS.SettingsProvider; using CMS.DataEngine; using CMS.GlobalHelper;
...
string bizFormName = "TestingSiteContactUs"; string siteName = "CMSTestingSite";
// Read Form definition BizFormInfo bfi = BizFormInfoProvider.GetBizFormInfo(bizFormName, siteName);
if (bfi != null) { // Read data type definition DataClassInfo dci = DataClassInfoProvider.GetDataClass(bfi.FormClassID);
if (dci != null) { // Get all Form data GeneralConnection genConn = ConnectionHelper.GetConnection(); DataSet ds = genConn.ExecuteQuery(dci.ClassName + ".selectall", null, null, null);
if (!DataHelper.DataSourceIsEmpty(ds)) { // Get ID of the first record int formRecordID = ValidationHelper.GetInteger(ds.Tables[0].Rows[0][0], 0);
BizFormItemProvider bProvider = new BizFormItemProvider();
// Get the record with ID of the first row record BizFormItem formRecord = bProvider.GetItem(formRecordID, dci.ClassName);
if (formRecord != null) // Set new field values formRecord.SetValue("FirstName", "Bob"); formRecord.SetValue("LastName", "Marley"); formRecord.SetValue("Email", "bob@email.com"); formRecord.SetValue("Message", "Good job:)"); formRecord.SetValue("FormUpdated", DateTime.Now);
// Save updates in the database formRecord.Update();
lblInfo.Text = "The first record was updated successfully."; } } else { lblInfo.Text = "No data found."; } } } |