Exploring the Command Object

A Command object is used to execute commands against a data store. Ideally, we will use this object to do our calls to the database to call stored procedures. You can also use it to send ad hoc commands to the database, such as inserts or updates. For example, a SQL command like "UPDATE location SET city = 'Edmonds'WHERE county = 'King'" would be executed using a Command object.

Listing 6.5 gives an example of the Command object.

Code Listing 6.5. The Command Object
1: Dim cmd as ADODB.Command
2: Dim rst as ADODB.Recordset
3: Set cmd = New ADODB.Command
4: cmd.ActiveConnection = "Provider=SQLOLEDB;DRIVER=SQL Server; SERVER=
(local);DATABASE=pubs;UID=sa;PWD=;" 5: cmd.CommandText = "SELECT au_lname FROM authors" 6: ...

Get Sams Teach Yourself Microsoft® Windows® DNA Programming in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.