Represents a Transact-SQL statement or stored procedure to execute against a SQL Server database. This class cannot be inherited.
See Also: SqlCommand Members
When an instance of System.Data.SqlClient.SqlCommand is created, the read/write properties are set to their initial values. For a list of these values, see the System.Data.SqlClient.SqlCommand constructor.
System.Data.SqlClient.SqlCommand features the following methods for executing commands at a SQL Server database:
SqlCommand.BeginExecuteNonQuery |
Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this System.Data.SqlClient.SqlCommand, generally executing commands such as INSERT, DELETE, UPDATE, and SET statements. Each call to SqlCommand.BeginExecuteNonQuery must be paired with a call to SqlCommand.EndExecuteNonQuery(IAsyncResult) which finishes the operation, typically on a separate thread. |
SqlCommand.BeginExecuteReader |
Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this System.Data.SqlClient.SqlCommand and retrieves one or more results sets from the server. Each call to SqlCommand.BeginExecuteReader must be paired with a call to SqlCommand.EndExecuteReader(IAsyncResult) which finishes the operation, typically on a separate thread. |
SqlCommand.BeginExecuteXmlReader |
Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this System.Data.SqlClient.SqlCommand. Each call to BeginExecuteXmlReader must be paired with a call to EndExecuteXmlReader, which finishes the operation, typically on a separate thread, and returns an System.Xml.XmlReader object. |
SqlCommand.ExecuteReader |
Executes commands that return rows. For increased performance, SqlCommand.ExecuteReader invokes commands using the Transact-SQL sp_executesql system stored procedure. Therefore, SqlCommand.ExecuteReader might not have the effect that you want if used to execute commands such as Transact-SQL SET statements. |
SqlCommand.ExecuteNonQuery |
Executes commands such as Transact-SQL INSERT, DELETE, UPDATE, and SET statements. |
SqlCommand.ExecuteScalar |
Retrieves a single value (for example, an aggregate value) from a database. |
SqlCommand.ExecuteXmlReader |
Sends the SqlCommand.CommandText to the SqlCommand.Connection and builds an System.Xml.XmlReader object. |
You can reset the SqlCommand.CommandText property and reuse the System.Data.SqlClient.SqlCommand object. However, you must close the System.Data.SqlClient.SqlDataReader before you can execute a new or previous command.
If a System.Data.SqlClient.SqlException is generated by the method executing a System.Data.SqlClient.SqlCommand, the System.Data.SqlClient.SqlConnection remains open when the severity level is 19 or less. When the severity level is 20 or greater, the server ordinarily closes the System.Data.SqlClient.SqlConnection. However, the user can reopen the connection and continue.
Nameless, also called ordinal, parameters are not supported by the .NET Framework Data Provider for SQL Server.