PRB: ODBC Reserved Word in a RFX Function Causes Syntax Error (125226)



The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), when used with:
    • Microsoft Visual C++ 1.51
    • Microsoft Visual C++, 32-bit Professional Edition 2.0

This article was previously published under Q125226

SYMPTOMS

An attempt to update a data source produces a command failed message box and MFC Trace output:
Syntax error in UPDATE statement.
State:37000,Native:-3503,Origin:
[Microsoft][ODBC Microsoft Access 2.0 Driver]

CAUSE

Using an ODBC reserved word as the second parameter (char* szName) in an RFX function causes the syntax error. The parameter represents the table's column name. For example, the following code causes the error:
void CMyRecordset::DoFieldExchange(CFieldExchange *pFX)
{
...

  RFX_Date(pFX, "date", ...); // error "date" is ODBC reserved word!

...
}
				
NOTE: Another scenario that will cause a similar error is caused by using a reserved Access word for a table name, then trying to insert the table via MFC and ODBC.

RESOLUTION

Implement one of the following solutions:

  • Change the name of the column in the data source's table. For example, change DATE to BIRTHDATE. DATE is a reserved word. -or-

  • Enclose the column name in square brackets when you use it in the RFX function in CRecordset::DoFieldExchange. For example:

    change this:
          RFX_Date (pFX, "Date",...);
    						
    to this:
          RFX_Date(...,"[Date]",...);
    						
    -or-

  • Qualify the column name with a table name (as MSQuery does) in the RFX function in CRecordset::DoFieldExchange. For example,

    Change this:
          RFX_Date(..., "Date",...);
    						
    to this:
          RFX_Date(..., "table1.Date",...);
    						

MORE INFORMATION

For a list of ODBC reserved words, see Appendix C of the ODBC Programmer's Reference.

Modification Type:MajorLast Reviewed:11/18/2003
Keywords:kbprb KB125226