Copied to clipboard

Flag this post as spam?

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


  • Craig O'Mahony 364 posts 918 karma points
    Mar 06, 2013 @ 15:14
    Craig O'Mahony
    0

    Running STP from Razor

    Hi is it possible to run a stored procedure from a razor file?

    What I've got so far is:

    @using System;
    @using System.Data;
    @using System.Configuration;
    @using System.Data.SqlClient;

    @{
    var db = Database.Open("zDevConnection");
    var param1 = "informationhere";
    var param2 = "informationhere";
    // or var param2 = 15247 (no quotes necessary if param is an integer datatype)
    var procRows = db.Query("Exec dbo.procName @RealParameterName1=@0, @RealParameterName2=@1", param1, param2);
    }
    <table>
    @foreach( var procRow in procRows )
    {
    <tr>
    <td>@procRow.ColumnName1</td>
    <td>@procRow.ColumnName2</td>
    <td>@procRow.ColumnName3</td>
    //etc
    </tr>


    }
    </table>

    But I'm getting an error of The name 'Database' does not exist in the current context

    I'm pretty sure that I'm missing an assembly reference but I don't know which one?

    Can I even do this?

    Thanks in advance

Please Sign in or register to post replies

Write your reply to:

Draft