BUG: "Syntax Error in PARAMETER clause" When Opening an MFC DAO RecordsetID: Q233972
|
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:
The error occurs when the parameter names for the query have a space in them; for example, "Param 1".Syntax error in PARAMETER clause
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".
Following are two ways to work around the problem:
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.
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().
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
Additional query words:
Keywords : kbDAO350 kbDatabase kbMFC kbAppWizard kbGrpVCDB
Version : winnt:6.0
Platform : winnt
Issue type : kbbug
Last Reviewed: June 23, 1999