asp.net.ph

IDbCommand Interface

System.Data Namespace


Represents an SQL statement that is executed while connected to a data source, and is implemented by .NET data providers that access relational databases.

IDbCommand Interface Members

Collapse   Properties

Visibility Name Value Type Accessibility
public CommandText String [ Get , Set ]
public CommandTimeout Int32 [ Get , Set ]
public CommandType CommandType [ Get , Set ]
public Connection IDbConnection [ Get , Set ]
public Parameters IDataParameterCollection [ Get ]
public Transaction IDbTransaction [ Get , Set ]
public UpdatedRowSource UpdateRowSource [ Get , Set ]

Collapse   Methods

Visibility Name Parameters Return Type
public Cancel ( ) Void
public CreateParameter ( ) IDbDataParameter
public ExecuteNonQuery ( ) Int32
public ExecuteReader ( ) IDataReader
public ExecuteReader ( CommandBehavior behavior ) IDataReader
public ExecuteScalar ( ) Object
public Prepare ( ) Void

Classes that Implement IDbCommand


Class Description
OleDbCommand Represents an SQL statement or stored procedure to execute at a data source.
SqlCommand Represents a Transact-SQL statement or stored procedure to execute at an SQL Server™ database. This class cannot be inherited.

Remarks

The IDbCommand interface allows 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 ADO.NET Commands. For more information about implementing .NET data providers, see Implementing a .NET Data Provider.

An application does not create an instance of the IDbCommand interface directly, but initializes an instance of a class that inherits IDbCommand.

Classes that inherit IDbCommand must implement the inherited members, and typically define additional members to add provider-specific functionality. For example, the IDbCommand 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 data providers, name the inheriting class in the form Prv Command where Prv is the uniform prefix given to all classes in a specific .NET data provider namespace. For example, Sql is the prefix of the SqlCommand class in the System.Data.SqlClient namespace.

When you inherit from the IDbCommand interface, you should implement the following constructors:


Item Description
PrvCommand ( ) Initializes a new instance of the PrvCommand class.
PrvCommand ( string cmdText ) 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.

Example

The following example initializes instances of the derived classes, SqlConnection, SqlCommand, and SqlDataReader. The example reads through the data, writing it to the page. Finally, the example closes the SqlDataReader, then the SqlConnection.

void ReadMyData ( string connString ) {
   string query = "SELECT OrderID, Customer FROM Orders";
   SqlConnection myConn = new SqlConnection ( connString );
   SqlCommand myCmd = new SqlCommand ( query, myConn );
   myConn.Open ( );
   SqlDataReader myReader = myCmd.ExecuteReader ( );
   try {
      while ( myReader.Read ( ) ) {
         Response.Write ( myReader.GetInt32 ( 0 ) + 
            ", " + myReader.GetString ( 1 ) );
      }
   }
   finally {
      // always close the reader when done.
      myReader.Close ( );
      // always close the connection when done.
      myConn.Close ( );
   }
}
  C# VB

See Also

DbDataAdapter   IDbConnection   OleDbCommand   SqlCommand Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph