System.Data.OleDb.OleDbCommand
Command objects are used to execute commands across a database connection
Command objects provide 3 methods that are used to exceute commands on the database
This can be used to execute stored procedures in the database.
Creating a Command Object
sSQLQuery = "SELECT Name FROM Clients WHERE ClientID=1"
objCommand = New System.Data.OleDb.OleDbCommand
objCommand.Connection = objConnectionObject
objCommand.CommandText = sSQLQuery
lNoOfRecords = objCommand.ExecuteNonQuery()
Alternatively you could pass these two parameters to the constructor.
Dim objCommand As New System.Data.OleDb.OleDbCommand(sSQLQuery, objConnectionObject)
lNoOfRecords = objCommand.ExecuteNonQuery()
sSQLQuery = "SELECT Name FROM Clients WHERE ClientID=1"
sName = objCommand.ExecuteScalar().ToString
Properties
| CommandText | The SQL text for the query. |
| CommandTimeout | The number of seconds after which the query times out. The default is 30 seconds. |
| CommandType | An enumerated value that specifies the type of the query: Text or StoredProcedure. |
| Connection | The connection object associated with this command. |
| Paramaters | The collection of parameters associated with this command. |
| Transaction | The transaction object corresponding to the transaction in which this command is executing. |
| UpdatedRowSource | Specifies how command results are applied to the DataRow object. This is only relevant when a command is associated with a DataAdapter that performs an update. |
Methods
| ExecuteNonQuery | Executes commands that have no return value, eg INSERT, UPDATE, DELETE. This returns the number of rows affected. |
| Cancel | Cancels the execution of the command object. |
| CreateParameter | Creates a parameter object connected to this parameterized command. |
| ExecuteReader | Executes a SELECT command that returns a resultset. This method returns a DataReader object. It is also possible to pass a CommandBehavior argument for extra control). |
| ExecuteScalar | Executes a SELECT command and returns the scalar value in the first column of the first row. |
| Prepare | Creates a compiled version of the command on the data source. Can only be used with stored procedures. |
| ResetCommandTimeout | Resets the CommandTimeOut property to its default of 30 seconds. |
Changing the Timeout
The CommandTimeout is not inherited from the ConnectionTimeout.
Setting the CommandTimeout equal to zero (0) indicates no timeout.
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext