Update Data

Updating Data from Code

Before you begin, make sure you have created a global data type "Demo.User" with one field of the String type named "Name" and some data or update the code in the sample to refer to an actual data type and its fields.

Sample:

using System.Linq;
using Composite.Data;

namespace Demo
{
    public class Class2
    {
        public static void UpdateData(string userOldName, string userNewName)
        {
            using (DataConnection connection = new DataConnection())
            {
                Demo.User myUser =
                   (from d in connection.Get<Demo.User>()
                    where d.Name == userOldName
                    select d).First();
                myUser.Name = userNewName;
                connection.Update<Demo.User>(myUser);
            }
        }
    }
}

Download the source

In this sample, we use DataConnection to query for a Demo.User (Get) with a specific name (Name), change it to a new name and update the Demo.User item in the CMS Data store (Update).

Read more on Composite.Data.DataConnection and its member methods

Please also see How to Update Data.