Microsoft KB Archive/233972

= BUG: "Syntax Error in PARAMETER clause" When Opening an MFC DAO Recordset =

Article ID: 233972

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Professional Edition

 Microsoft Visual C++ 6.0 Standard Edition 

-

<div class="notice_section">

This article was previously published under Q233972

<div class="symptoms_section">

SYMPTOMS
When opening an MFC DAO Recordset on an Microsoft Access parameterized query in an MFC AppWizard project, the application displays a message box containing the following error:

Syntax error in PARAMETER clause

The error occurs when the parameter names for the query have a space in them; for example, "Param 1".

<div class="cause_section">

CAUSE
CDaoRecordset does not build the PARAMETERS clause correctly. For example, the following SQL statement may be constructed: PARAMETERS Some Param Text; SELECT * from [AccessQuery] The syntax error occurs because of the space between "Some" and "Param".

<div class="resolution_section">

RESOLUTION
Following are two ways to work around the problem:

  You can change the string returned from the GetDefaultSQL function from the following CString CAccessParamSet::GetDefaultSQL {  return _T("[AccessQuery]"); } to the following: CString CAccessParamSet::GetDefaultSQL {  return _T("select * from [AccessQuery]"); } This prevents MFC from constructing a "PARAMETERS" clause as part of the SQL statement. -or-

</li>  You can change the DDX function for the parameter in the DoFieldExchange function to include square brackets around the parameter name. For example, in the recordset's DoFieldExchange function, change the following DFX_Text(pFX, _T("param 1"), m_param_1); to the following: DFX_Text(pFX, _T("[param 1]"), m_param_1); You may encounter additional problems if the wizard mapped the DFX_Text function to a numeric parameter. The DFX_Text function attempts to construct a PARAMETERS clause with "text" as the data type. If the parameter is really a number, you will get a datatype mismatch. You may want to suppress the creation of a PARAMETERS clause in the SQL statement by implementing the first workaround or you may want to use a different DFX function, such as DFX_Long instead of DFX_Text. </li></ul>

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

<div class="moreinformation_section">

Steps to Reproduce Behavior

 * 1) Create a query in Microsoft Access that contains an input parameter.
 * 2) Create an MFC AppWizard project that accesses the query created in step 1.
 * 3) Run the Application.

Keywords: kbappwizard kbbug kbdatabase kbprb KB233972

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.