In addition to the Command object, an application can use the Connection object to issue commands, stored procedures, and user-defined functions to a database as if they were native methods on the Connection object. To execute a query without using a Command object, an application can pass a query string to the Execute method of a Connection object.
However, a Command object is required if you want to save and re-execute the command text, or use query parameters.
To execute a command on the Connection object
This example shows how to use the Execute method of the Connection object to execute commands.
Dim cn As New ADODB.Connection
. . .
Dim rs As New ADODB.Recordset
cmd1 = txtQuery.Text
Set rs = cn.Execute(cmd1)
After the Connection and Recordset objects are created, the variable cmd1 is assigned the value of a user-supplied query string (txtQuery.Text) from a Microsoft Visual Basic® form. The recordset is assigned the results of a query, by calling the Execute method of the Connection object, with the variable cmd1 used as the query string parameter.