I'd like to run a query against the SQL database. Specifically, I want
select max(updateDate) from cmsDocument
As I understand it, I need an SqlConnection object to execute the query. I suppose Umbraco already has a connection, if I only can get hold of it?
(Based on the assumption that this SQL query is faster than looping through all the documents. I hear something about documents being cached, so maybe not?)
Querying the SQL database?
I'd like to run a query against the SQL database. Specifically, I want
select max(updateDate) from cmsDocument
As I understand it, I need an
SqlConnection
object to execute the query. I suppose Umbraco already has a connection, if I only can get hold of it?(Based on the assumption that this SQL query is faster than looping through all the documents. I hear something about documents being cached, so maybe not?)
You can use DatabaseContext that already has sqlconnection:
And for ignorants like myself, I have to add
I got it working with
My
reader
is an Umbraco object, while Marcio'sresult
is I think a C# object? The latter is more tempting to me.I didn't find documentation for neither object, but I suppose Visual studio will help me out with
Query
objects, too.What version of umbraco are you using? This code is using legacy api. I've never used it that way.
7.1.8
var db = ApplicationContext.Current.DatabaseContext.Database;
var query = new Sql("select max(updateDate) from cmsDocument");
var cmsData = db.Fetch(query);
1) - please refer this query => "db.Fetch
( This will fetch max update date from your table, note: - u must have to specify your model name through which data will be bind )
is working on a reply...