Code examples

  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 examples show how you can use the CMS.DataEngine library for low-level data manipulation.

 

 

 

Only for illustration

 

The code is used only for illustration. It's recommended that you use the CMS.SiteProvider.UserInfoProvider class for manipulation of the user data.

 

 

Creating a new user

 

[C#]

 

using CMS.DataEngine;

...

 

DataClass userObj = new DataClass("cms.user");

userObj.SetValue("username", "johns");

userObj.SetValue("fullname", "John Smith");

userObj.Insert();

 

Selecting and updating an existing user

 

[C#]

 

using CMS.DataEngine;

...

 

DataClass userObj = new DataClass("cms.user", 10);

string userName = (string) userObj.GetValue("username");

userObj.SetValue("fullname", "John Smith Jr.");

userObj.Update();

 

Deleting a user

 

[C#]

 

using CMS.DataEngine;

...

DataClass userObj = new DataClass("cms.user", 10);

if (! userObj.IsEmpty())

{

  userObj.Delete();

}

 

Running a custom query

 

You can run a custom query if you first create it either manually in the CMS_Query table or through the administration interface (if it’s supported for the chosen entity).

 

[C#]

 

using CMS.DataEngine;

...

GeneralConnection cn = ConnectionHelper.GetConnection();

DataSet ds = null;

object[,] parameters = new object[1, 3];

 

parameters[0, 0] = "@UserName";

parameters[0, 1] = "johns";

 

ds = cn.ExecuteQuery("cms.user.selectbyname", parameters);

 

Page url: http://devnet.kentico.com/docs/devguide/index.html?data_layer_code_examples.htm