MDAC 2.5 SDK - ADO
Step 2: Create a Command (ADO Tutorial)
See Also
You are Here...
- Make a connection to a data source.
- Optionally, create an object to represent an SQL query command.
- Optionally, specify values in the SQL command as variable parameters.
- Execute the command. If the command is row-returning, store the rows in a storage object.
- Optionally, navigate, examine, manipulate, and edit the data.
- If appropriate, update the data source with changes from the storage object. Optionally, embed the update in a transaction.
- If a transaction was used, accept or reject the changes made during the transaction. End the transaction.
Discussion
A command is an instruction understood by the data provider that will modify, manage, or manipulate the data source. Commands are typically written in SQL, although no particular command language is required. A query command requests that the data provider return a Recordset object containing rows of information.
Specify a command as either:
- Command text, that is, a literal string, or a variable that represents the string.
- An object that represents the command. In this case, it is the value of a Command object CommandText property set to the command text.
See the sidebar for a brief discussion of parameterized commands.
This tutorial queries for all the information in the Authors table of the Pubs database. The Command object is declared, set with the open Connection object, and the command text. The code looks like this:
Dim cmd As New ADODB.Command
Set cmd.ActiveConnection = cnn
cmd.CommandText = "SELECT * from Authors"
Next Step 3: Execute the Command