SqlCommand |
marshal by reference, disposable |
System.Data.SqlClient (system.data.dll) |
sealed class |
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( string cmdText);
public SqlCommand(string cmdText, SqlConnection connection);
public SqlCommand(string cmdText, SqlConnection connection, SqlTransaction transaction);
// Public Instance Properties
public string CommandText{set; get; } // implements System.Data.IDbCommand
public int CommandTimeout{set; get; } // implements System.Data.IDbCommand
public CommandType CommandType{set; get; } // implements System.Data.IDbCommand
public SqlConnection Connection{set; get; }
public bool DesignTimeVisible{set; get; }
public SqlParameterCollection Parameters{get; }
public SqlTransaction Transaction{set; get; }
public UpdateRowSource UpdatedRowSource{set; get; } // implements System.Data.IDbCommand
// Public Instance Methods
public void Cancel( ); // implements System.Data.IDbCommand
public SqlParameter CreateParameter( );
public int ExecuteNonQuery( ); // implements System.Data.IDbCommand
public SqlDataReader ExecuteReader( );
public SqlDataReader ExecuteReader(System.Data.CommandBehavior behavior);
public object ExecuteScalar( ); // implements System.Data.IDbCommand
public XmlReader ExecuteXmlReader( );
public void Prepare( ); // implements System.Data.IDbCommand
public void ResetCommandTimeout( );
}
Hierarchy
System.Object
System.MarshalByRefObject System.ComponentModel.Component(System.ComponentModel.IComponent, System.IDisposable)
SqlCommand(System.Data.IDbCommand, System.ICloneable)
Returned By
SqlCommandBuilder.{GetDeleteCommand( )
, GetInsertCommand( )
, GetUpdateCommand()
, SqlConnection.CreateCommand( )
, SqlDataAdapter.{DeleteCommand
, InsertCommand
, SelectCommand
, UpdateCommand}
, SqlRowUpdatedEventArgs.Command
, SqlRowUpdatingEventArgs.Command
Passed To
SqlCommandBuilder.DeriveParameters( )
, SqlDataAdapter.{DeleteCommand
, InsertCommand
, SelectCommand
, SqlDataAdapter( )
, UpdateCommand}
, SqlRowUpdatingEventArgs.Command
|