asp.net.ph

OleDbCommand Class

System.Data.OleDb Namespace


Represents an SQL statement or stored procedure to execute at a data source.

OleDbCommand Class Members

Collapse   Constructors

Visibility Constructor Parameters
public OleDbCommand ( )
public OleDbCommand ( String cmdText )
public OleDbCommand ( String cmdText , OleDbConnection connection )
public OleDbCommand ( String cmdText , OleDbConnection connection , OleDbTransaction transaction )

Collapse   Properties

Visibility Name Value Type Accessibility
public CommandText String [ Get , Set ]
public CommandTimeout Int32 [ Get , Set ]
public CommandType CommandType [ Get , Set ]
public Connection OleDbConnection [ Get , Set ]
public DesignTimeVisible Boolean [ Get , Set ]
public Parameters OleDbParameterCollection [ Get ]
public Transaction OleDbTransaction [ Get , Set ]
public UpdatedRowSource UpdateRowSource [ Get , Set ]

Collapse   Methods

Visibility Name Parameters Return Type
public Cancel ( ) Void
public Clone ( ) OleDbCommand
protected CreateDbParameter ( ) DbParameter
public CreateParameter ( ) OleDbParameter
protected Dispose ( Boolean disposing ) Void
protected ExecuteDbDataReader ( CommandBehavior behavior ) DbDataReader
public ExecuteNonQuery ( ) Int32
public ExecuteReader ( CommandBehavior behavior ) OleDbDataReader
public ExecuteReader ( ) OleDbDataReader
public ExecuteScalar ( ) Object
public Prepare ( ) Void
public ResetCommandTimeout ( ) Void

Remarks

When an instance of OleDbCommand is created, the read/write properties are set to their initial values. For a list of these values, see the OleDbCommand constructor.

OleDbCommand features the following methods to execute commands at a data source:

Item Description
ExecuteReader Executes commands that return rows. ExecuteReader may not have the desired effect if used to execute commands such as SQL SET statements.
ExecuteNonQuery Executes commands such as SQL INSERT, DELELE, UPDATE, AND SET statements.
ExecuteScalar Retrieves a single value ( for example, an aggregate value ) from a database.

If a fatal OleDbException ( for example, an SQL Server™ severity level of 20 or greater ) is generated by the method executing an OleDbCommand, the OleDbConnection, the connection may be closed. However, the user can reopen the connection and continue.

Example

The following example uses the OleDbCommand, along OleDbDataAdapter and OleDbConnection, to select rows from an Access database. The filled DataSet is then returned. The example is passed an initialized DataSet, a connection string, a query string that is an SQL SELECT statement, and a string that is the name of the source database table.

void ReadMyData ( string connString ) {
   string query = "SELECT OrderID, CustomerID FROM Orders";
   OleDbConnection myConn = new OleDbConnection ( connString );
   OleDbCommand myCommand = new OleDbCommand ( query, myConn );
   myConn.Open ( );
   OleDbDataReader myReader = myCommand.ExecuteReader ( );

   try {
      while ( myReader.Read ( ) ) {
         Response.Write ( myReader.GetInt32 ( 0 ) + ", " + myReader.GetString ( 1 ) );
      }
   }
   finally {
      myReader.Close ( );
      myConn.Close ( );
   }
}
  C# VB

See Also

OleDbDataAdapter   OleDbConnection 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