Add Data
Adding 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" or updated the code in the sample to refer to an actual data type and its fields.
Sample:
using Composite.Data; namespace Demo { public class Class1 { public static void AddData(string userName) { using (DataConnection connection = new DataConnection()) { Demo.User myUser = DataConnection.New<Demo.User>(); myUser.Name = userName; myUser = connection.Add<Demo.User>(myUser); } } } }
In this sample, we use DataConnection
to create a new Demo.User (New
), set its field (Name
) and add it to the CMS Data store (Add
).
Read more on Composite.Data.DataConnection and its member methods
Please also see How to Add Data.