API
Version 7.x > API > Get custom table items View modes: 
User avatar
Member
Member
JamesIT - 2/14/2014 11:38:22 PM
   
Get custom table items
I have created a custom table. I want to retrieve all records in the custom table.
I used the GetItems() method to retrieve the record.

DataSet dsItems = customTableProvider.GetItems(customTableClassName, null, null);

But the dsItems return null. Although the custom table existed in the database.

I also tried with the example code in
http://devnet.kentico.com/docs/devguide/index.html?custom_tables_api_examples_managing_custom_table_data.htm
but the result is still NULL.
I tried to use the DeleteItems() method to remove the records is Ok. But the GetItems() method is not.
Please help me. Thanks a lot

User avatar
Kentico Support
Kentico Support
kentico_romank - 2/15/2014 1:13:39 AM
   
RE:Get custom table items
Hi,

If you go to Site Manager -> Development -> Custom tables, are you able to see the table in the list? Also could you please clarify that custom table code name (displayed in Site Manager) is same as the value passed to the GetItems method?

Did you follow the example in Developers guide step by step? If not could you please just copy and paste the code on the page?

Best Regards,
Roman Konicek

User avatar
Member
Member
JamesIT - 2/15/2014 3:15:40 AM
   
RE:Get custom table items
Hi Roman,
Thanks for your reply. I'm sure I did follow the example in Developers guide step by step.
I used the example code in the Developers guide just to check GetItems() method
but the result is still null.
I used another way to get data is Ok. but I want to know why i can't get the data by the GetItems() method.
DataSet always return is null.

This is the code I used to check:


private bool GetAndUpdateCustomTableItem()
{
// Creates a new Custom table item provider
CustomTableItemProvider customTableProvider = new CustomTableItemProvider(CMSContext.CurrentUser);

string customTableClassName = "customtable.Test";

// Checks if Custom table 'Sample table' exists
DataClassInfo customTable = DataClassInfoProvider.GetDataClass(customTableClassName);

if (customTable != null)
{
// Gets the data set according to the parameters
DataSet dataSet = customTableProvider.GetItems(customTableClassName, null, null);

if (!DataHelper.DataSourceIsEmpty(dataSet))
{
// Gets the custom table item ID
int itemID = ValidationHelper.GetInteger(dataSet.Tables[0].Rows[0][0], 0);

// Gets the custom table item
CustomTableItem updateCustomTableItem = customTableProvider.GetItem(itemID, customTableClassName);

if (updateCustomTableItem != null)
{
return true;
}
}
}
return false;

}

User avatar
Kentico Support
Kentico Support
kentico_romank - 2/15/2014 6:38:05 AM
   
RE:Get custom table items
Hi James,

Could you please add the following code into the example above, just at the beginning of the method:
bool allowed = CustomTableItemProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.CustomTables, VersionActionEnum.Edit);

What is the value of allowed variable?

Regards,
Roman Konicek

User avatar
Member
Member
JamesIT - 2/15/2014 7:58:45 AM
   
RE:Get custom table items
Hi Roman,
Now I knew the reason. Thanks so much.