I have the following code:
@helper RetrievePhotoWithName(int userid)
{
var database = Database.Open("SC");
var name = database.QuerySingle("select FirstName, LastName, ProfilePicture from UserProfile where UserId = @0", userid);
var notifications = database.Query("SELECT COUNT(*) FROM NotificationsTable WHERE UserID = @0 AND MessageWasRead = @1", userid, false);
var DisplayName = "";
if(notifications < 1)
{
DisplayName = name["FirstName"] + " " + name["LastName"];
}
else
{
DisplayName = name["FirstName"] + ", you have " + notifications + " new messages.";
}
<a href="@Href("~/Home")" title="My Account"><img src="@Href("~/Shared/Assets/Images/" + name["ProfilePicture"] + ".png")" id="MiniProfilePicture" /> @DisplayName</a>
database.Close();
}
which is supposed to count all the rows in my table and either display a “new notifications” message to the user on the web page or just display their name, but it’s not working.
Do not edit this question. The reason I am re-posting this question is because my previous one was changed which resulted in inaccurate responses.
Since
SELECT COUNT(*)is returning a single scalar value, I think you want to usedatabase.QueryValue()instead:http://msdn.microsoft.com/en-us/library/webmatrix.data.database.queryvalue(v=vs.99).aspx