I’ve coded a class which uses connection to the WebMatrix database. I can greatly do insert, update queries, but I have an issue with select queries.
I can’t assign the Razor dynamic variable to my type-specified variable.
How to use the WebMatrix database in an usual c# class?
My code from the class:
public bool verify_session()
{
if (get_user_id() > 0)
{
return true;
}
if (HttpContext.Current.Request.Cookies["session_id"] != null)
{
var db = Database.Open("studia_sesje");
var data = db.QuerySingle("SELECT session_id, user_id FROM sessions WHERE session_id = '" + HttpContext.Current.Request.Cookies["session_id"] + "'");
_session_id = (string)data.session_id;
_user_id = (int)data.user_id;
return true;
}
return false;
}
the error is
Cannot perform runtime binding on a null reference
The error says that the result of your
QuerySinglemethod call was null, or no rows in your database were returned. You should check the data is not null before trying to access dynamic properties: