Commands are issued against databases to do actions against data stores. For example, you may execute a command that inserts data, or a command that deletes data. For more information on easily moving data in and out of databases read the topic <a href="updatedatafromdb.aspx">"Updating data in a database"</a>.
Commands include any command that can be issued against a database, and in the case of the ADOCommand, can be data store specific. For example, you may issue a stored procedure call for a command, or perhaps a command to "set quoted_identifiers on". Whatever the command may be, the ADOCommand or SQLCommand can be used to get the command to your back end data store.
<p>
ADO classic allowed several different ways to issue commands, through the Command object, Connection object or Recordset object. In ADO+, it is the Command object only that executes commands. This specific task based approach may not initially be suited to your style of using ADO, but we believe in the long run, there is a huge benefit to having targeted objects for specific jobs.
<p>
In order to issue a command against a database, the command object must have two basic things: a Connection and CommandText. Both of these can be set in the constructor:
<P>
<div class=code>
SQLCommand myCommand = new SQLCommand("Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')", myConnection);
</div>
<p>
You can pass a different connection to the Command when using the Execute method.
To execute the command you simply call the Execute method.
<P>
<div class=code>
myCommand.Execute();
</div>
<p>
The ADOCommand and SQLCommand objects have parameter collection which behave just like the parameter collections from ADO classic. You can pass your parameters in-line: