locked
Displaying Paramaterized Oracle SQL data using Razor RRS feed

  • Question

  • User-37964247 posted

    My data base is very simple Cust_code is numeric value here is my code

    @{
        Layout = "~/_SiteLayout.cshtml";
        Page.Title = "Customer Data";
        }

    @{
        var Customer = @AppState["Customer"];
        var db = Database.Open("ConnectionString");

        var data = db.Query("SELECT  UCRACCT_CUST_CODE,UCRACCT_PREM_CODE,UCRACCT_STATUS_IND,UCRACCT_CYCL_CODE,UCRACCT_ESTABLISHED_DATE FROM UCRACCT WHERE UCRACCT_CUST_CODE = @0 ",Customer);
         }

    <html>
     <body>
          <p>Customer: @AppState["Customer"]</p>
          <p> Status: @AppState["Status"]</p>
        
     <table>
        <tr>
         <th>Custe</th>
         <th>Prem</th>
         <th>Status</th>
         <th>Cycle</th>
         <th>Established</th>
        </tr>
            @foreach(var row in data)
             {
                <tr>
                    <td>@row.UCRACCT_CUST_CODE</td>
                    <td>@row.UCRACCT_PREM_CODE</td>
                    <td align="center">@row.UCRACCT_STATUS_IND</td>
                    <td align="center">@row.UCRACCT_CYCL_CODE</td>
                    <td>@row.UCRACCT_ESTABLISHED_DATE</td>
                </tr>
             }
     </table>
     </body>
     </html>

    <p>
          This web page was built using ASP.NET Web Pages. For more information, visit the
        <a href="http://www.asp.net">ASP.NET homepage</a>.
    </p>

    For some reason I can't get it to work I get the error "

    ORA-01036: illegal variable name/number"

    if I enter the customer code as 

    WHERE UCRACCT_CUST_CODE = 12345

    instead of

    WHERE UCRACCT_CUST_CODE = @0

    it works but if I try to read the parameter it doesn't work... This seems simple enough and easy to be solved... any ideas?

    Tuesday, May 6, 2014 1:14 PM

Answers

  • User1853794821 posted

    For openers, get rid of the "@" in "var Customer = @AppState["Customer"];"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 6, 2014 1:27 PM