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
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.)