The first problem in your question is the way you queries a Database object in Web Pages.
As you can see (
Database Class[
^]) there are three methods to execute a query:
Query, to obtain a list of rows as
IEnumerable<object>
;
QuerySingle, to obtain a single row as
object
;
QueryValue, to obtain a single scalar value.
The Execute method executes a non-query SQL statement, instead.
So, if you want to obtain a list of row you should query your database with this statement:
var q = db.Query("SELECT ... ");
and if you want to obtain your rows sequentially you should use this block of code:
@foreach(var row in q){
<p>row.FieldName</p>
}
Otherwise, if you want to access your rows randomly, you should convert the IEnumerable to a List:
var q = db.Query("SELECT ... ").ToList();
and then you can use statements like
<p>@q[20].FieldName</p>