custom table data

Esakki raj asked on February 19, 2019 13:58

how to write query in ascx file for selecting data from the custom table

Correct Answer

Dragoljub Ilic answered on February 19, 2019 15:30

In reference to this post, you can use Kentico ConnectionHelper to achieve this:

DataSet ds = ConnectionHelper.ExecuteQuery("select * from CMS_User", null, QueryTypeEnum.SQLQuery)

1 votesVote for this answer Unmark Correct answer

Recent Answers


Dragoljub Ilic answered on February 19, 2019 14:25

Hi,

I don't know which version of kentico you are using, but with the code bellow you can achive that in version 11. This should give you a good start how to use data from custom tables in kentico:

// Prepares the code name (class name) of the custom table
string customTableClassName = "customtable.sampletable";

// Gets the custom table
DataClassInfo customTable = DataClassInfoProvider.GetDataClassInfo(customTableClassName);
if (customTable != null)
{
    // Gets a custom table record with a specific primary key ID (25)
    CustomTableItem item1 = CustomTableItemProvider.GetItem(25, customTableClassName);

    // Gets the first custom table record whose value in the 'ItemName' field is equal to "SampleName"
    CustomTableItem item2 = CustomTableItemProvider.GetItems(customTableClassName)
                                                        .WhereEquals("ItemName", "SampleName")
                                                        .FirstObject;

    // Loads a string value from the 'ItemText' field of the 'item1' custom table record
    string itemTextValue = ValidationHelper.GetString(item1.GetValue("ItemText"), "");
}

Best regards, Dragoljub

1 votesVote for this answer Mark as a Correct answer

Esakki raj answered on February 19, 2019 14:50

hi Dragoljub, i dont have the class for the custom tables.how to get the data without using the tableClassName

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.