C# 查询数据库文件时出现问题;使用 WHERE 子句时出现问题
我正在我的 C# 代码中使用 odbc 查询 dbase .dbf 文件,并且在查询中使用“where”子句时遇到问题。如果我只是“从 FILE.DBF 中选择 *”,我就可以很好地检索和读取记录,并且当我搜索答案时我在网页上看到的每个示例都显示了这么多语法。我尝试了多种使用“where”构造 select 语句的方法,但到目前为止它们都失败了。所以,我想知道我是否不能在针对数据库文件的查询中使用“where”子句,或者我是否只是还没有找到正确的语法。
我已经尝试过:
select * from FILE.DBF where GROUP = 21;
select * from FILE.DBF where GROUP = '21';
select * from FILE.DBF where GROUP = "21";
所有这些的结果是错误:ERROR [42000] [Microsoft][ODBC dBase Driver] WHERE 子句中的语法错误。
任何帮助将不胜感激。
I'm querying a dbase .dbf file with odbc from within my c# code and am having a problem using a 'where' clause in my query. I can retrieve and read the records fine if I just 'select * from FILE.DBF', and every example I see on web pages as I search for an answer show just that much syntax. I've tried multiple ways of constructing the select statement with a 'where' and so far they all fail. So, I'm wondering whether I just can NOT use a 'where' clause in a query against a dbase file, or whether I simply haven't hit on the correct syntax yet.
I've tried:
select * from FILE.DBF where GROUP = 21;
select * from FILE.DBF where GROUP = '21';
select * from FILE.DBF where GROUP = "21";
The result of all of these is the error: ERROR [42000] [Microsoft][ODBC dBase Driver] Syntax error in WHERE clause.
Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试用方括号将 GROUP 一词括起来...如 ..
select * from FILE.DBF where [GROUP] = 21;
GROUP 是一个 SQL 关键字,它很可能会导致一些问题。
Try surrounding the word GROUP with brackets ... as in ..
select * from FILE.DBF where [GROUP] = 21;
GROUP is a SQL keyword and it's most likely causing some issues.
GROUP 是用于 SQL 本身的关键字。尝试运行相同的查询,但使用不同的“where”子句,通过用另一个字段替换“Group”(当然,也有不同的条件)。如果查询有效,则“GROUP”与 GROUP BY 的 SQL 语法混合在一起,因此您可能需要使用方括号或其他字符来括住字段名称。
GROUP is a keyword used for SQL itself. Try running the same query but with a different 'where' clause, by substituting 'Group' with another field instead (and a different condition too, naturally). If the query works, then 'GROUP' is being mixed up with the SQL syntax for GROUP BY, and thus you might need to use brackets or some other character to enclose the field name.