CreateQuery Method (Remote Data)

       

Creates a new query object and adds it to the rdoQueries collection.

Syntax

object.CreateQuery Name, SQLString

The CreateQuery method syntax has these parts:

Part Description
object An object expression that evaluates to an rdoConnection object
Name Required. A string expression that evaluates to the name for the new object
SQLString Optional. SQL query for the new prepared statement

Remarks

The CreateQuery method creates a new rdoQuery object for this connection and adds it to the rdoQueries collection. You can also declare stand-alone rdoQuery objects using the Dim statement as follows:

Dim myQuery as New rdoQuery

Stand-alone rdoQuery objects are not associated with a connection until you set the ActiveConnection property.

The rdoQuery corresponds to the ODBC prepared statement used to define a reusable SQL query that can contain parameters.  You can execute the rdoQuery any number of times, and pass parameters that are substituted into the SQL statement before it is executed.  Parameters are maintained in the rdoParameters collection.  Generally, if you intend to execute a query more than once in your code, it is more efficient to use rdoQuery objects than to use the Execute or OpenResultset method on objects other than the rdoQuery.

The value passed for the Name parameter can be used with the Item method to locate the new object in its collection. If Name is not provided, the rdoQuery is appended to the rdoQueries collection, and the rdoQuery can be used by referencing the query variable or the rdoQuery object’s ordinal value. If the object specified by name is already a member of the rdoQueries collection (including an empty string), a trappable error occurs.  All rdoQuery objects are temporary — they are discarded when the rdoConnection object is closed.

To remove an rdoQuery object from an rdoQueries collection, use the Close method on the rdoQuery.

The SQLString parameter is optional, but if not provided, you must set the SQL property of the resulting rdoQuery object before executing it.

Use the Execute method to run an SQL statement in an rdoQuery object that does not return rows (an action query).  Use the OpenResultset method to run an rdoQuery that returns rows.

If there is an unpopulated rdoResultset pending on a data source that can only support a single operation on an rdoConnection object, you cannot create additional rdoQuery or rdoResultset objects, or use the Refresh method on the rdoTable object until the rdoResultset is flushed, closed, or fully populated.  For example, when using SQL Server 4.2 as a data source, you cannot create an additional rdoResultset object until you move to the last row of the current rdoResultset object.  To populate the result set, use the MoreResults method to move through all pending result sets, or use the Cancel or Close method on the rdoResultset to flush all pending result sets.