Kentico CMS 6.0 Developer's Guide

Code examples

Code examples

Previous topic Next topic Mail us feedback on this topic!  

Code examples

Previous topic Next topic JavaScript is required for the print function 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;

...

 

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

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

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

userObj.Insert();

 

Selecting and updating an existing user

 

[C#]

 

using CMS.DataEngine;

...

 

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

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

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

userObj.Update();

 

Deleting a user

 

[C#]

 

using CMS.DataEngine;

...

SimpleDataClass userObj = new SimpleDataClass("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;

...

QueryDataParameters parameters = new QueryDataParameters();

parameters.Add("@UserName", "johns");

 

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