查询时出错

时间:2013-08-08 16:07:19

标签: c# sql ms-access

我正在使用VS 2012 C#WinForms Application查询名为AC_ECONOMIC的访问表。这是我的代码,

con6 = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath);
//string propQuery = String.Format("SELECT PROPNUM FROM [AC_ECONOMIC]");// WHERE SECTION = 4 AND QUALIFIER = CGA0112");

ad6.SelectCommand = new OleDbCommand("SELECT DISTINCT PROPNUM FROM [AC_ECONOMIC] WHERE SECTION = 4 AND QUALIFIER = '" + qual0 + "'", con6);

ds6.Clear();
con6.Open();
ad6.SelectCommand.ExecuteNonQuery(); //ERROR HERE
ad6.Fill(ds6);
con6.Close(); 

我一直收到错误,

  

“IErrorInfo.GetDescription因E_FAIL(0x80004005)而失败。”

如果我从查询中取出SECTION = 4 AND,它不会给我错误,但这不是我想得到的特定数据。可以告诉我为什么我收到这个错误?任何帮助都会很棒。

1 个答案:

答案 0 :(得分:2)

SECTION是一个保留的访问关键字,尝试将其包含在方括号或反引号中:

WHERE [SECTION] = 4

or

WHERE `SECTION` = 4