此查询在 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 中的样子:
最佳答案
TO也是Access中的保留字。尝试将其替换为类似 tbl_Org
的内容。
关于c# - SELECT 语句中的 OleDbCommand 语法错误 0x80040E14,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42017103/