Name
SqlCommand
Synopsis
This class represents a Transact-SQL command or stored procedure that
can be executed against a SQL Server data source. For information
about the basic SqlCommand methods and properties,
refer to the reference for the
System.Data.IDbCommand interface, which
SqlCommand implements.
SqlCommand errors result in a
SqlException being thrown.
The order of parameters isn’t important with the
SqlCommand when you create a parameterized query
or stored procedure. To create a parameterized query, set
CommandType to
System.Data.CommandType.Text and name all
parameters. For example, you can set the
CommandText to:
SELECT * FROM Customers WHERE CustomerID = @CustomerID
to specify that a CustomerID value will be
supplied as a parameter with the name @CustomerID
.
The SqlCommand class also adds an
ExecuteXmlReader( ) method, which executes a
SELECT query that uses the FOR XML clause to return the results in an
XML document. You can access the nodes of this document in a
forward-only, node-by-node basis using the
System.Xml.XmlReader instance that
ExecuteXmlReader( ) returns. For more information
about the FOR XML clause, refer to Chapter 17 or
SQL Server 2000 Books Online.
public sealed class SqlCommand : System.ComponentModel.Component, System.Data.IDbCommand, ICloneable { // Public Constructors public SqlCommand( ); public SqlCommand(stringcmdText); public SqlCommand(stringcmdText, SqlConnectionconnection); public SqlCommand(stringcmdText, SqlConnectionconnection, SqlTransaction ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access