感谢您抽出宝贵时间查看我的帖子。 我已经提供了我所阅读的内容的链接,以尝试解决此问题以及我使用的学习材料。
以下是我遇到问题的代码。我尝试了不同的代码排列以使其工作,我相信主要问题在于我的变量设置。我正在查询外部Oracle数据库。
@{
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>
以下将以我希望的方式进行工作
@{
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);
}
但是当我将其更改为以下内容时,它会突然出现以下错误:
@{
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:非法变量名称/编号
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);
将行修改为如下所示。即使尝试在参数字段中传递静态值也不适合我。
var selectedData = db.Query(searchQuery,"A00000000");
我已经验证了此查询在我对查询进行硬编码时使用Webmatrix返回数据。
var searchQuery= "SELECT * FROM DATABASENAME.DATABASETABLE WHERE UNIQUE ID = 'A00000000'"
var selectedData = db.Query(searchQuery);
我尝试了几种不同的方法来引用@ 0,并在设置值后为搜索词添加单引号。任何帮助将不胜感激!
System.Data.OracleClient.OracleException:ORA-01036:非法变量名称/编号 HTML ORA-01036:非法变量名称/编号 ASP非法变量名称/编号 ASP DB.Query()
Db.Query参数
System.Data.OracleClient.OracleException: ORA-01036: illegal variable name/number(不同的语法/语言)
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
What is the Equivalent of ObjectQuery.Parameters in DbQuery
http://www.asp.net/web-pages/overview/getting-started/introducing-aspnet-web-pages-2/displaying-data(通读并主动编写本教程。)
答案 0 :(得分:1)
您提到过您尝试了几种引用参数的方法。但是,这是Oracle,它们使用:0进行参数化。你试过吗
var searchQuery = "SELECT * FROM DATABASE.DATABASETABLE WHERE UNIQUEID = ':0'";
:0参数只是将传递的字符串删除到sql字符串中。