Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Snow lizard 36 posts 106 karma points
    Nov 04, 2014 @ 10:40
    Snow lizard
    0

    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>

    }
    }

    }

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Nov 04, 2014 @ 22:49
    Andy Butland
    0

    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>
Please Sign in or register to post replies

Write your reply to:

Draft