Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Parameters and ASP.NET Razor syntax

Tony DunsworthDec 3 2013

I'm re-writing some pages from classic ASP to Razor .cshtml pages and I'm running into a problem trying to insert parameters in my query. I can write the query directly with SQL Developer and it works just fine. However, when I write it for .NET's Razor syntax I receive ORA-00936 errors. I've cross posted this to the ASP.NET forum as well, but am not getting responses which fit Oracle. The pages connect to a 11g database.

The intent is to have a default set of data load then allow the user to input date parameters to change the range of the search. The cdts column is a VARCHAR2 formatted as "YYYYDDMMHH24mmssTZX" with the last 3 characters in the string being the Time Zone abbreviation. However, all my users need to add for search is year month day and hour in 24 format.

The relevant code is as follows:

@{

   var copyYear = DateTime.Now.Year;

   var connString = string.Format("USER ID=XXX;Password=XXX;Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = HOST.INFORMATION.ORG)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = SERVICE.HOST.ORG)))");

   var providerName = "Oracle.DataAccess.Client";

   var db = Database.OpenConnectionString(connString, providerName);

   var sDate = DateTime.Now.AddDays(-1).ToString("YYYYMMDDHH");

   var fDate = DateTime.Now.ToString("YYYYMMDDHH");

   var rows = db.Query("SELECT DISTINCT l.cdts AS cdts, r.user_comment AS comments, p.lname AS last_name, p.fname AS first_name, l.cpers AS cpers, l.eid AS eid FROM state_log l, state_resp r, persl p WHERE l.cdts BETWEEN @0 AND @1 AND l.cpers=p.empid AND l.rec_num=r.rec_num AND r.user_comment NOT LIKE ('%KCJIS%') AND r.user_comment NOT LIKE ('%Validate%') AND r.user_comment NOT LIKE ('%REJIS%') AND r.user_comment NOT LIKE ('%ILEADS%') AND r.user_comment NOT LIKE ('%Password%') AND r.user_comment NOT LIKE ('%PERSO%') AND r.user_comment NOT LIKE ('%VEHIC%') ORDER BY l.cdts DESC", sDate, fDate);

  

}


The html code for the form and the table are:

<div class="row">

  <form class="form-inline" method="post" name="addressSearch" action="address_search.cshtml">

  <label for="sDate">Start Date:</label>

  <input type="text" class="input-medium" placeholder="YYYYMMDDHH" name="sDate">

  <label for="fDate">End Date:</label>

  <input type="text" class="input-medium" placeholder="YYYYMMDDHH" name="fDate">

  <label for="txtaddy">Address:</label>

  <input type="text" class="input-large" name="txtaddy">

  <button type="submit" class="btn btn-primary">Search</button>

  </form>

  </div>

  <div class="row">

  <table class="table table-bordered table-striped table-condensed" id="paged">

  <thead>

  <tr>

  <th>Date &amp; Time</th>

  <th>Address</th>

  <th>Officer Name</th>

  <th>Officer ID</th>

  <th>Event No.</th>

  </tr>

  </thead>

  <tbody>

   @foreach(var row in rows) {

  <tr>

  <td>@row.cdts</td>

  <td>@row.user_comment</td>

  <td>@row.first_name @row.last_name</td>

  <td>@row.cpers</td>

  <td><a href="http://jcsoarch:8081/details.cshtml?nbr=@row.eid">@row.eid</a></td>

  </tr>

  }

  </tbody>

  </table>

  </div>


Thank you for anyone who can help me figure out how to get the parameters into the query properly.

The first vars for the connection string, etc work perfectly in other pages where I do not need to add parameters from the user.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 31 2013
Added on Dec 3 2013
0 comments
2,849 views