Original post address: http://devnet.kentico.com/Knowledge-Base/API-and-Internals/Using-the-data-layer-API-to-query-your-Kentico-dat.aspx
This article describes how to make use of the kentico API to perform complex queries or create generic code that queries both system and Custom tables.
For system tables related to objects with info classes, you can access the data using providers, such as userinfoprovider (for instance, to retrieve a userinfo object to access data from cms_user table ).
Database Table API documentation
You can also make use of the data layer API. The CMS. dataengine class can allow you more
Flexibility than using providers. You can perform more complex queries, generate queries within code, and query both system and Custom tables.
Code examples for 5.5r2
Code examples for 6.0
Code example for 7.0
For more complex queries and queries against custom tables, you can use the executequery method. see the last example in the above documentation. the query you call must exist in the cms_query table. by default any custom tables will have
Least A selectall method.
Keep in mind that from 6.0 on, you need to use a querydataparameters object, but in 5.5r2 or earlier, you wocould use a generic object. in either case, you will want to establish a general connection:
Generalconnection Cn = connectionhelper. getconnection ();
Then execute the query using that connection:
CN. executequery (...)