Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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:
var db = ApplicationContext.Current.DatabaseContext.Database;
var result = db.Query<DateTime>("select max(updateDate) from cmsDocument");
And for ignorants like myself, I have to add
modificationStamp = result.ElementAt<DateTime>(0);
I got it working with
reader = umbraco.BusinessLogic.Application.SqlHelper.
ExecuteReader("select max(updateDate) as modified from cmsDocument");
modificationStamp = reader.GetDateTime("modified") ;
My reader is an Umbraco object, while Marcio's result 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.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted