0

I am trying to join 3 tables in my MS Access database in C#. Whenever I run the code, i get an error saying "Missing Operator in query expression". I have also just copied the SQL statement directly into MS Access and ran it, and it returned the same error, since I was thinking it may have been a formatting issue in VS.

The actual SQL statement that causes the error:

SELECT Products.ProductName, Keys.Key, Keys.Active, Transactions.Total, Transactions.TransactionDate
FROM Keys
INNER JOIN Transactions 
ON Keys.TransactionID = Transactions.TransactionID 
INNER JOIN Products 
ON Transactions.ProductID = Products.ProductID
WHERE Transactions.UserID = 20

The SQL statement inside of Visual Studio:

command.CommandText =
"SELECT Products.ProductName, Keys.Key, Keys.Active, Transactions.Total, Transactions.Date " +
"FROM Keys " +
"INNER JOIN Transactions ON Keys.TransactionID = Transactions.TransactionID " +
"INNER JOIN Products ON Transactions.ProductID = Products.ProductID " +
"WHERE Transactions.UserID = " + UserID;
OleDbDataReader reader = command.ExecuteReader();

  • 1
    Set up your joins in the Access query designer. It will add parentheses as required to keep the db engine happy. – HansUp Nov 17 '22 at 14:56
  • Yes, use query designer to construct SQL. Access SQL is picky about parentheses around JOIN clauses. It will also throw in a bunch of unnecessary parens in WHERE clause. – June7 Nov 17 '22 at 15:53

0 Answers0