FIX: Visual Studio .NET Query Builder builds incorrect syntax for Jet queries that involve joins (318646)
The information in this article applies to:
- Microsoft Visual Studio .NET (2002), Professional Edition
This article was previously published under Q318646 SYMPTOMS If you use the Query Builder tool as part of the Data
Adapter Configuration Wizard for the OLEDBDataAdapter object, and you connect to a Microsoft Access database with the
Microsoft Jet OLEDB provider, query syntax that involves more than one table
join may be generated incorrectly. This will result in an error that resembles
the following (table and column names are for illustration purposes only):
Syntax error (missing operator) in query expression
'Employees.EmployeeID = Orders.EmployeeID INNER JOIN [Order Details] ON
Orders.OrderID = [Order Details].OrderID INNER JOIN Customers ON
Customers.CustomerID = Orders.CustomerID This problem occurs when
there is more than one JOIN clause in the query. CAUSE The query is missing the parentheses that must be present
for the Jet engine to parse the query properly. RESOLUTION Changing the query in the Query Builder or the Data Adapter
Configuration Wizard does not prevent this error because the Wizard resets the
query to the incorrect syntax. However, you can edit the query that
the Wizard generates in the "Windows Form Designer Generated Code" section in
either of the following ways:
- Add nested parentheses around the JOIN clauses; for
example:
SELECT * FROM
(((Table1 INNER JOIN Table2 ON Column = Column) INNER JOIN
Table3 ON Column = Column) INNER JOIN Table4 ON Column = Column) ...
- Change the query to specify its joins in the WHERE clause
as follows:
SELECT * FROM Table1, Table2, Table3, Table4
WHERE Table1.Column = Table2.Column
AND Table2.Column = Table3.Column
AND Table3.Column = Table4.Column
AND ...
To make such a change, follow these steps:
- Open the code window of the form with the DataAdapter control that contains the SELECT command that contains
joins.
- Expand the region with the label "Windows Form Designer
generated code".
- Find the statement that assigns the command text to the Command object used by the DataAdapter; for example:
Me.OleDbSelectCommand1.CommandText = "SELECT Customers.Address, Customers.City,...
- Edit the SELECT statement specified in one of the two ways
shown earlier.
Note that reinvoking the Data Adapter Configuration Wizard or
the Query Builder on this OleDbDataAdapter object may remove these changes. STATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed at the beginning of this article.
This bug was corrected in Visual Studio .NET 2003.
Modification Type: | Minor | Last Reviewed: | 9/15/2005 |
---|
Keywords: | kbvs2002sp1sweep kbbug kbpending KB318646 |
---|
|