c# - SELECT 语句中的 OleDbCommand 语法错误 0x80040E14

标签 c# winforms oledbdataadapter

此查询在 Access 2010 中完美运行:

SELECT te.[EnterpirseName], COUNT(to.[ID]) AS Orgs, SUM(to.[Members]) AS Mems
FROM tbl_Enterprise AS te, tbl_Organizations AS to
WHERE to.[Enterprise_ID] = te.[ID] AND te.[Status] = 1
GROUP BY te.[EnterpirseName]

但是,当我尝试从我的 C# winforms 应用程序执行它时,出现语法错误:

0x80040E14 关键字 FROM 附近的语法错误

编辑:我的 C# 代码:

string strCommand = "SELECT te.[EnterpirseName], COUNT(to.[ID]) AS Orgs, SUM(to.[Members]) AS Mems" +
    " FROM tbl_Enterprise AS te, tbl_Organizations AS to" +
    " WHERE to.[Enterprise_ID] = te.[ID]" +
    " AND te.[Status] = 1" +
    " GROUP BY te.[EnterpirseName]";

DataTable dt = new DataTable();

using (OleDbConnection conn = new OleDbConnection(strConnString))
{
    OleDbDataAdapter da = new OleDbDataAdapter(strCommand, conn);

    using (DataSet ds = new DataSet())
    {
        // THIS IS WHERE I GET THE ERROR
        da.Fill(ds);
        dt = ds.Tables[0];
    }
}

这就是 strCommand 在 Debug 中的样子:

enter image description here

最佳答案

TO也是Access中的保留字。尝试将其替换为类似 tbl_Org 的内容。

关于c# - SELECT 语句中的 OleDbCommand 语法错误 0x80040E14,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42017103/

相关文章:

c# - Java servlet 中的 session 对象、cookie 与 ASP .NET

c# - 是否可以在应用程序设置中使用自定义枚举? (VS10)

c# - Excel 文件 - 它已经被另一个用户以独占方式打开,

c# - 导出扩展名为 .xlsx 的 Excel 文件

c# - NServiceBus 指定处理程序执行的顺序

c# - Format Line 实际上没有格式化。

c# - Linq to Entities 奇怪的部署行为

vb.net - .NET 中 ByVal 和 ByRef 没有区别吗?

c# - 在 WinForms 输入焦点上自动弹出平板电脑触摸键盘

c# - DataAdapter.Fill(数据集)