|
||
The following examples show how you can use the CMS.DataEngine and CMS.SettingsProvider libraries 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.
|
[C#]
using CMS.DataEngine; ...
// create a new object based on the cms.user data class IDataClass userObj = DataClassFactory.NewDataClass("cms.user"); // Set some values. The first parameter of the SetValue method accepts database column names that belong to the particular object. userObj.SetValue("UserName", "johns"); userObj.SetValue("FullName", "John Smith"); // insert the new user into the database, in this case, the CMS_User table userObj.Insert(); |
[C#]
using CMS.DataEngine; ...
// prepare the user's ID int userId = 10;
// get the object from database according to the data class name and ID IDataClass userObj = DataClassFactory.NewDataClass("cms.user", userId); // acquire the user's name string userName = userObj.GetValue("UserName").ToString(); // change the user's full name userObj.SetValue("FullName", "John Smith"); // update the database record userObj.Update(); |
[C#]
using CMS.DataEngine; ... // prepare the user's ID int userId = 10;
// get the object from the database IDataClass userObj = DataClassFactory.NewDataClass("cms.user", userId); // if the object exists, delete it if (userObj != null) { userObj.Delete(); } |
You can run a custom query if you first create it either manually in the CMS_Query table or through the administration interface (if this is supported for the given entity).
[C#]
using CMS.SettingsProvider; ... QueryDataParameters parameters = new QueryDataParameters(); parameters.Add("@UserName", "administrator");
DataSet ds = SqlHelperClass.ExecuteQuery("cms.user.selectbyusername", parameters, null, null); |