Sorry for asking a question that has probably been answered but I have searched everywhere with no luck. All I want to do is query the database which is stored in APP_DATA as Umbraco. The table that I have added is called courses. The below code fails here:
vardb=Database.Open("Umbraco");
I dont know how to get to the logs to find a detailed description for this.
So, my questions are:
1, How can I query the database?
2, How do I grab value from a form that has been posted?
You can than do things like this in Razor (copied from one of my packages):
//This sql get's all the newest versions of the documents which store the DAMP xml and contain the id of the current media item.
string sql = string.Format(@"
select cpd.contentNodeId as nodeId, cpd.dataNText as xmlValue, cpt.Alias as propertyAlias from cmsDocument cd
inner join cmsPropertyData cpd ON cd.nodeId = cpd.contentNodeId
inner join cmsPropertyType cpt ON cpd.propertytypeid = cpt.id
where cd.newest = 1
and cd.versionId = cpd.versionId
and cpd.dataNtext like '<DAMP fullMedia="""">%'
and cpd.dataNtext like '%{0}%'", media.Id);
List<DAMP_UpdateDocument> updateDocuments = new List<DAMP_UpdateDocument>();
using (IRecordsReader dr = SqlHelper.ExecuteReader(sql))
{
while (dr.Read())
{
try
{
//Get the documents which need to be updated.
updateDocuments.AddRange(DAMP_Helper.GetUpdateDocuments(dr.GetString("xmlValue"), dr.GetInt("nodeId"), dr.GetString("propertyAlias"), media.Id));
}
catch (Exception ex)
{
//If the xml can't be converted log it and go to the next row.
DAMP_Helper.LogException(ex);
}
}
}
Query the database from cshtml
Hello,
Sorry for asking a question that has probably been answered but I have searched everywhere with no luck. All I want to do is query the database which is stored in APP_DATA as Umbraco. The table that I have added is called courses. The below code fails here:
var db = Database.Open("Umbraco");
I dont know how to get to the logs to find a detailed description for this.
So, my questions are:
1, How can I query the database?
2, How do I grab value from a form that has been posted?
Many thanks in advance.
Mark
//My code so far
@using System.Linq
@using WebMatrix.Data;
@{
var ermsg ="";
try
{
var db = Database.Open("Umbraco");
ermsg="There is no error in code";
}
catch
{
ermsg="Error in code! ";
}
}
<html>
<head>
<title>Displaying Data </title>
</head>
<body>
<h1>keyStages</h1>
<div id="grid">
@ermsg
</div>
</body>
</html>
Umbraco has a helper which you can use:
You can than do things like this in Razor (copied from one of my packages):
Jeroen
Hi Jeroen,
That is a very detailed anwser and looks like it could work for me. I will try this later!
Thanks for your time!
is working on a reply...