2

This query runs perfectly in 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]

However when I try to execute it from my C# winforms application, I get syntax error:

0x80040E14 Syntax error near keyword FROM

EDIT: My C# code:

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];
    }
}

That's how strCommand looks like in Debug:

enter image description here

Muhammed Shevil KP
  • 1,404
  • 1
  • 16
  • 21
firefalcon
  • 500
  • 2
  • 8
  • 21

2 Answers2

2

TO is a reserved word in Access as well. Try to replace it to something like tbl_Org.

FireFalcon
  • 831
  • 11
  • 23
-2

Are you sure your c# app isn't using another engine, like SQL Server? In SQL Server, TO is a reserved word, so you should use [To] instead.

faibistes
  • 125
  • 6