1

Thank you for taking the time to view my post. I have provided links of what I have read to try and resolve this problem as well as the learning material I have used.

The following is the code I am having an issue with. I have tried varied permutations of this code to get it to work and I believe the main problem lies within my variable setting. I am querying an external Oracle database.

    @{
    var db = Database.Open("DBNAME");
    var searchterm = "";
    var searchQuery = "SELECT * FROM DATABASE.DATABASETABLE WHERE UNIQUEID = @0";
    if (!Request.QueryString["searchterm"].IsEmpty()){
        searchterm = Request.QueryString["searchterm"];
                                                      }
  var selectedData = db.Query(searchQuery);
  var grid = new WebGrid(source: selectedData);  



}

<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Movies</title>

    </head>
    <body>
            <form method ="get">
                <label for="searchterm">Please enter you UNIQUEVALUE</label>
                <input type="text" name="searchterm" value="@Request.QueryString["searchterm"]" />
                <input type="submit" value="Search UNIQUEVALUE" />

            </form>
        <div>
                    @grid.GetHtml()
        </div>
    </body>
</html>

The following will work about the way I want it to

@{
 var db = Database.Open("DBNAME");
        var searchterm = "";
        var searchQuery = "SELECT * FROM DATABASE.DATABASETABLE WHERE UNIQUEID = 'A00000000'";
        if (!Request.QueryString["searchterm"].IsEmpty()){
            searchterm = Request.QueryString["searchterm"];
                                                        }
      var selectedData = db.Query(searchQuery);
      var grid = new WebGrid(source: selectedData); 

}

But when I change it to the following it breaks with the this error:

@{
        var db = Database.Open("DBNAME");
        var searchterm = "";
        var searchQuery = "SELECT * FROM DATABASE.DATABASETABLE WHERE UNIQUEID = @0";
        if (!Request.QueryString["searchterm"].IsEmpty()){
            searchterm = Request.QueryString["searchterm"];
                                                        }
      var selectedData = db.Query(searchQuery,searchterm);
      var grid = new WebGrid(source: selectedData);  


}

System.Data.OracleClient.OracleException: ORA-01036: illegal variable name/number

Line 7:              searchQuery = "SELECT * FROM DATABASE.DATABASETABLE WHERE UNIQUEID = @0";                                            
Line 8:                                                          }
***Line 9:        var selectedData = db.Query(searchQuery,searchterm);***
Line 10:       var grid = new WebGrid(source: selectedData);  

Modified the line to look like below. Even trying to pass a static value in a parameter field is not working out for me.

var selectedData = db.Query(searchQuery,"A00000000");

I have verified this query returns data using Webmatrix when I hard code the query.

var searchQuery= "SELECT * FROM DATABASENAME.DATABASETABLE WHERE UNIQUE ID = 'A00000000'"
 var selectedData = db.Query(searchQuery);

I have tried several different ways of quoting the @0, and adding single quotes to search term after the value has been set. Any help would be greatly appreciated!

Leaning/Research/Articles Read:

Searches done on Stack Overflow:

System.Data.OracleClient.OracleException: ORA-01036: illegal variable name/number HTML ORA-01036: illegal variable name/number\ ASP illegal variable name/number ASP DB.Query()

Searches done on Google:

Db.Query Parameters

Articles read on Stack overflow:

System.Data.OracleClient.OracleException: ORA-01036: illegal variable name/number (different syntax/language)

https://stackoverflow.com/questions/31398488/adding-parameters-to-db-query-using-webmatrix

Constructing a good search query using system.data.oracleclient

Win32Exception (0x80004005): The wait operation timed out

Connecting html pages + Razor to database

Passing parameters to db.query with arangojs

Articles read on google:

What is the Equivalent of ObjectQuery.Parameters in DbQuery

https://social.msdn.microsoft.com/Forums/en-US/91c7fb6d-d1b8-4a7f-aec9-16336dbd619b/access-to-dbquery-parameters-for-logging?forum=adodotnetentityframework

Learning Material used to get this far:

http://www.asp.net/web-pages/overview/getting-started/introducing-aspnet-web-pages-2/displaying-data (read through, and actively coded with this tutorial.)

1 Answer 1

1

You mentioned that you tried several ways to quote the parameter. However, this is Oracle and they use a :0 for the parameterization. Did you try

var searchQuery = "SELECT * FROM DATABASE.DATABASETABLE WHERE UNIQUEID = ':0'";

The :0 parameter just drops the passed string into the sql string.

Oracle parameter binding

Sign up to request clarification or add additional context in comments.

4 Comments

Hi Knox! Thank you for reviewing my question. I have tried that method. var searchterm = "A00000000"; var searchQuery = "SELECT * FROM DATABASE.DATABASETABLE WHERE UNIQUEID = '@0'"; var selectedData = db.Query(searchQuery,searchterm); I have also tried the following: var searchTerm= "''A00000000'"; var selectQuery = "SELECT * FROM DATABASE.DATABASETABLE WHERE UNIQUEID = '@0'"; And this as well: var searchTerm= "'"; var selectQuery = "SELECT * FROM DATABASE.DATABASETABLE WHERE UNIQUEID = '@0'"; searchTerm = "'" + Request.QueryString[searchterm"]; + "'"
most of the examples are for SQL Server. Oracle uses a colon instead of the at sign for parameterization. You might not need the single quotes, so give that a try too.
Knox! YOU'RE MY HERO. Changing the positional parameter to :0 allowed the query to go through. Would you be able to put me in the right direction for the documentation you used? I would like to reference it in the future.
Since you had pointed out that the one difference was oracle, and i had a difference experience with a different database where the parameterization didn't work, I looked at stack overflow for parameters and Oracle. The link is at the bottom of my updated answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.