I have a CSHTML Script a Pal has written, I am making some changes, I have a SQL Query as a variable and if this SQL query returns NULL then I want to display separate HTML than to if it returns results. I have copied out the relevant parts of the code below.
@{
var db = Database.Open("3.2.0"); //db holds Database to Open
var sql = "select ticketid, Title, description, category, updatedon, updatedby, severity from dbo._ServiceStatus "; //Sql To Pass through
}
@if (@sql == null) {
<h3>There are no issues at the moment</h3>
}
else{
foreach(var row in db.Query(sql)) //for each row returned in the SQL Query
{
<div class='box_lrg'><div class='box_top'></div><div class='box_middle'>
<h2 class="title">@row["Title"]</h2>
<p class="ticket">TicketID: @row["TicketId"]</p>
<div class="clear"></div>
<p class="description">@row["Description"]</p>
<p class="updatedon"><em>Updated On:</em><br />@row["UpdatedOn"]</p>
<p class="updatedby"><em>Updated By:</em><br />@row["UpdatedBy"]</p>
<p class="severity"><em>Severity:</em><br />@row["Severity"]</p>
</div><div class='box_bottom'><p class="category">Category: @row["Category"]</p>
</div></div>
}
}
It all runs good except the h3 tag stating "there are no issues" does not show when that table is empty.
Any ideas welcome