PRB: Migrating SQL Statements with Quotes From DAO to ADOID: Q181832
|
ActiveX Data Objects (ADO) imposes no restrictions on the syntax used to generate a recordset or execute a statement. This comes from the underlying native provider, such as the OLE DB provider for Index Server, or the OLE DB provider for ODBC drivers. Valid syntax required for using ADO successfully is defined by the underlying OLE DB provider. When migrating SQL syntax to ADO, you will need to consider this for SQL statements such as the following, which works when using DAO to go to the Microsoft Access Jet engine:
INSERT INTO Authors ( Au_ID, Author ) VALUES ( 54, "Record # 54" )
However, with ADO (to the OLE DB provider for ODBC drivers through the
Microsoft Access ODBC driver) this syntax generates an error and fails to
execute.
Instead, you have to use the following syntax:Too few parameters. Expected 1.
INSERT INTO Authors ( Au_ID, Author ) VALUES ( 54, 'Record # 54' )
This is only one example and specific to DAO/Jet.
You should examine the Online help for the underlying provider and for the datastore it exposes in order to determine the correct syntax to provide your ADO code. As in the preceding case, even though DAO and the Microsoft Access ODBC Driver both use Jet, the syntax differs slightly in order for the Microsoft Access ODBC Driver to meet the ODBC specification.
This behavior is by design.
Errors raised by the provider (or the datastore it exposes) are stored in the ADO Errors collection. Whereas errors raised by ADO are exposed by the native error handling of the language you are using. For Visual Basic for Applications (VBA) and/or VBScript this is the Err object. For C++ or Java this is typically some kind of exception, although with C++ you may just have to check for a failed HRESULT if manipulating ADO directly through COM.
For additional information, please see the following article in the Microsoft Knowledge Base:
Q178070 HOWTO: Handle Quotes and Pipes in Concatenated SQL Literals
Q167957 INFO: Extracting Error Information from ADO in VB
Additional query words:
Keywords :
Version : WINDOWS:1.0,1.5
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: May 3, 1999