[英]C# OleDb select query throws missing operator exception
I'm currently connecting to and working with a MS Access database. 我目前正在连接并使用MS Access数据库。 I can do a generic select * query fine, so I am connected to the db, but when I try to select using parameters it throws a missing operator exception.
我可以做一个通用的select *查询,所以我连接到db,但是当我尝试选择使用参数时,它会抛出一个缺少的运算符异常。
string selectStatement = "Select ID from pages where page_title = ? limit 1";
string title = Request.QueryString["pagetitle"];
OleDbCommand selectCommand = new OleDbCommand(selectStatement, conn);
selectCommand.Parameters.Add("@p1",OleDbType.VarChar);
selectCommand.Parameters["@p1"].Value = System.Web.HttpUtility.UrlDecode(title);
OleDbDataReader selectResult = selectCommand.ExecuteReader();
The error I get is on the ExecuteReader line: 我得到的错误是在ExecuteReader行:
Exception Details: System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression 'page_title = ? limit 1'.
I've tried using @p1 inside the query, as well as the current ?. 我试过在查询中使用@ p1,以及当前的? I've tried adding the parameters different ways, including removing the @ in the parameter name.
我尝试以不同的方式添加参数,包括删除参数名称中的@。 Nothing seems to work.
似乎没什么用。 Can someone point me in the right direction?
有人能指出我正确的方向吗?
AFAIK, there is no LIMIT
clause in MS Access. AFAIK,MS Access中没有
LIMIT
子句。
And, parameters should be named, @p1
in your case, instead of ?
并且,参数应该在您的情况下命名为
@p1
,而不是?
I haven't worked with Access for years, so I might be wrong, but instead of LIMIT
, try this: 我多年没有使用Access,所以我可能错了,但不是
LIMIT
,试试这个:
Select TOP 1 ID from pages where page_title = @p1
Also, if appropriate, consider this advice: 此外,如果合适,请考虑以下建议:
MS Access isn't quite the right DBMS to handle websites (I suspect in your case it's a website). MS Access不是处理网站的正确DBMS(我怀疑在你的情况下它是一个网站)。 For an alternative file-based database management systems, check SQLite and FirebirdSQL .
对于替代的基于文件的数据库管理系统,请检查SQLite和FirebirdSQL 。 Both have a lot of tools you can use for GUI, like SQLite Maestro, and respectively IBExpert.
两者都有许多可用于GUI的工具,如SQLite Maestro和IBExpert。
Queries are more flexible in those DBMS. 这些DBMS中的查询更灵活。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.