Search code examples
c#sqldbase

C# problem querying dbase file; problem using WHERE clause


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.


Solution

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