Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Tips Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS Access
SQL Scripts & Samples
» Database Forum
» Slideshows
» Sitemap
Free Newsletters:

News Via RSS Feed

Database Journal |DBA Support |SQLCourse |SQLCourse2

Featured Database Articles

MS Access

Posted May 30, 2000

Introduction to Database Manipulation with ADO - Page 5

By Benoy Jose

The Command Object

The Command object represents a command. The ResultSet and the Connection objects execute SQL commands which are command strings. Instead of the Command string a Command object can be used. The Command string can be anything from a simple SQL command to a complex stored procedure. But this does not make the Command object anything special as the RecordSet can do all this too. The Command object is best used for complex stored procedures with in parameters and out parameters. The Command object can be used to execute bulk operations and manipulate the structure of the database.

Click here for code example 5.

Command object methods and properties:

The first step is to specify the ActiveConnection we want to use as specified in line 3. Once we have established the active connection we can use the Command object in the same way as the Connection object. We don't need to explicitly open the data source or close it after use, we can use the execute method directly as in line 6.

The different properties of the Command object help us specify some parameters outside the Execute method to get more control over the operation; like in line 4 we have specified the Command text and in line 5 we have indicated the Command Type as a stored Procedure. We can also specify the CommandTimeout property. This determines how long ADO has to wait for the command to execute. The default value is 30. If the value is set to 0 ADO will wait indefinitely until the command executes.

The command object has methods like CreateParameter which creates a new parameter object in the Parameters collection and an Execute method that runs the SQL statement or stored procedure specified in the CommandText.

MS Access Archives

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Latest Forum Threads
MS Access Forum
Topic By Replies Updated
Help With Microsoft Access kasy 0 September 4th, 07:35 PM
Linked table not sorting or filtering - ODBC error Java 1 August 28th, 10:37 AM
Use Parameter in select statement (Sql in Microsoft Access) katty.jonh 1 July 25th, 06:45 AM
Query Issue algebroni 7 July 23rd, 04:22 PM