Retrieve reserved column name value using db.Query
Hi i'm trying to retrieve records from my database which works fine if the table name is e.g id for example but I have a table column name of [7] which doesn't bring back a value and displays WebMatrix.Data.DynamicRecord.[7] on the page. How would I get this value?
Here is my code. Thanks
@using System.Linq
@using WebMatrix.Data
@{
var connstr = System.Configuration.ConfigurationManager.AppSettings["umbracoDbDSN"];
using (var db = Database.OpenConnectionString(connstr,"System.Data.SqlClient"))
{
var logs = db.Query("select top 100 * from tableName order by id DESC");
Retrieve reserved column name value using db.Query
Hi i'm trying to retrieve records from my database which works fine if the table name is e.g id for example but I have a table column name of [7] which doesn't bring back a value and displays WebMatrix.Data.DynamicRecord.[7] on the page. How would I get this value?
Here is my code. Thanks
@using System.Linq
@using WebMatrix.Data
@{
var connstr = System.Configuration.ConfigurationManager.AppSettings["umbracoDbDSN"];
using (var db = Database.OpenConnectionString(connstr,"System.Data.SqlClient"))
{
var logs = db.Query("select top 100 * from tableName order by id DESC");
@foreach(var log in logs) {
<td>@log.id</td>
<td>@log.[7]</td>
}
}
}
Thanks kind of an odd name for a table!... maybe if you can't change it though, you could alias it?
E.g.
select top 100 id, [7] as ColumnSeven from tableName order by id DESC
And then render it with:
<td>@log.ColumnSeven</td>
is working on a reply...