I am trying to make a simple display of some data from the Umbraco database, using only Razor, but it fails...
What am I doing wrong? I made a Partial View with the following code.
/Daniel
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var DB = Database.Open("umbracoDbDSN");
var DataTypes = DB.Query("SELECT * FROM cmsDataType");
}
@{
foreach (var item in DataTypes)
{
@item
}
}
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: Navnet 'Database' findes ikke i den aktuelle sammenhæng
Source Error:
Line 4:
Line 5: @{
Line 6: var DB = Database.Open("umbracoDbDSN");
Line 7: var DataTypes = DB.Query("SELECT * FROM cmsDataType");
Line 8:
I'm afraid I don't speak what looks like German so I'm having to rely on Google Translate, which says that message means "Does not exist in current context".
Based on that I suspect you might be missing a reference/using statement in order to user the Database static class.
What if you do something like this would this work for you.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var db = Umbraco.Core.ApplicationContext.Current.DatabaseContext.Database;
var dataTypes = db.Query("SELECT * FROM cmsDataType");
}
@{
foreach (var item in dataTypes)
{
@item
}
}
Graeme W - it now complains about the Open statement.
Dennis - It did not work.
Compiler Error Message: CS1061: 'Umbraco.Web.UmbracoHelper' does not contain a definition for indeholder ikke en definition til 'Core', og der blev ikke fundet en udvidelsesmetode 'Core', der accepterer et første argument af typen 'Umbraco.Web.UmbracoHelper' (mangler du en 'using'-direktiv eller en assemblyreference?)
Charles - I would like to make a comment function, and the first step is to access the DB. Do you have an other surgestion, that does not involve C#?
Razor database connection to Umbraco DB
Hi,
I am trying to make a simple display of some data from the Umbraco database, using only Razor, but it fails...
What am I doing wrong? I made a Partial View with the following code.
/Daniel
When you say it fails, what do you mean?
Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
I'm afraid I don't speak what looks like German so I'm having to rely on Google Translate, which says that message means "Does not exist in current context".
Based on that I suspect you might be missing a reference/using statement in order to user the Database static class.
I have some views where I use peta poco and according to my comments I needed to include this declaratioin
This is on version 6
Hi Daniel,
What if you do something like this would this work for you.
Hope this helps,
/Dennis
Out of interest why are you accessing the database directly?
Nik, it is Danish and you got it right.
Graeme W - it now complains about the Open statement.
Dennis - It did not work.
Charles - I would like to make a comment function, and the first step is to access the DB. Do you have an other surgestion, that does not involve C#?
Thank you all for your answers :-)
Hi Daniel,
I think that you need these namespaces
That being said, could it be an option to have a custom table in the Umbraco database, then try see Warrens blog post here http://creativewebspecialist.co.uk/2013/07/16/umbraco-petapoco-to-store-blog-comments/
Or here is a video that shows how to get data from a custom table.
https://www.aptitude.co.uk/videos/using-custom-tables-data-in-umbraco/
Hope this helps,
/Dennis
Thank you! I think this will get me what i want :-)
/Daniel
is working on a reply...