Represents an SQL statement that is executed while connected to a data source, and is implemented by .NET Framework data providers that access relational databases.
Assembly: System.Data (in System.Data.dll)
Thetype exposes the following members.
|CommandText||Gets or sets the text command to run against the data source.|
|CommandTimeout||Gets or sets the wait time before terminating the attempt to execute a command and generating an error.|
|CommandType||Indicates or specifies how the CommandText property is interpreted.|
|Connection||Gets or sets the IDbConnection used by this instance of the .|
|Parameters||Gets the IDataParameterCollection.|
|Transaction||Gets or sets the transaction within which the Command object of a .NET Framework data provider executes.|
|UpdatedRowSource||Gets or sets how command results are applied to the DataRow when used by the Update method of a DbDataAdapter.|
|Cancel||Attempts to cancels the execution of an .|
|CreateParameter||Creates a new instance of an IDbDataParameter object.|
|Dispose||Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.)|
|ExecuteNonQuery||Executes an SQL statement against the Connection object of a .NET Framework data provider, and returns the number of rows affected.|
|ExecuteReader()||Executes the CommandText against the Connection and builds an IDataReader.|
|ExecuteReader(CommandBehavior)||Executes the CommandText against the Connection, and builds an IDataReader using one of the CommandBehavior values.|
|ExecuteScalar||Executes the query, and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.|
|Prepare||Creates a prepared (or compiled) version of the command on the data source.|
The interface enables an inheriting class to implement a Command class, which represents an SQL statement that is executed at a data source. For more information about Command classes, see Executing a Command.
An application does not create an instance of the interface directly, but creates an instance of a class that inherits .
Classes that inherit must implement all inherited members, and typically define additional members to add provider-specific functionality. For example, the interface defines the ExecuteNonQuery method. In turn, the SqlCommand class inherits this method, and also defines the ExecuteXmlReader method.Notes to Implementers
To promote consistency among .NET Framework data providers, name the inheriting class in the form PrvClassname where Prv is the uniform prefix given to all classes in a specific .NET Framework data provider namespace. For example, Sql is the prefix of the SqlCommand class in the System.Data.SqlClient namespace.
When you inherit from the interface, you should implement the following constructors:
Initializes a new instance of the PrvCommand class.
Initializes a new instance of the PrvCommand class with the text of the query.
PrvCommand(string cmdText, PrvConnection connection)
Initializes a new instance of the PrvCommand class with the text of the query and a PrvConnection.
PrvCommand(string cmdText, PrvConnection connection, PrvTransaction transaction)
Initializes a new instance of the PrvCommand class with the text of the query, a PrvConnection, and the PrvTransaction.
The following example creates instances of the derived classes, SqlConnection, SqlCommand, and SqlDataReader. The example reads through the data, writing it to the console. Finally, the example closes the SqlDataReader, then the SqlConnection.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)