Skip Headers

Oracle Data Provider for .NET Developer's Guide
Release 9.2.0.2

Part Number A96160-01
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to beginning of chapter Go to next page

Oracle.DataAccess.Client Namespace, 3 of 26


OracleCommandBuilder Class

An OracleCommandBuilder object provides automatic SQL generation for the OracleDataAdapter when updates are made to the database.

Class Inheritance

Object

  MarshalByRefObject

    Component

      OracleCommandBuilder

Declaration
// C#
public sealed class OracleCommandBuilder : Component
Thread Safety

All public static methods are thread-safe, although instance methods do not guarantee thread safety.

Remarks

OracleCommandBuilder automatically generates SQL statements for single-table updates when the SelectCommand property of the OracleDataAdapter is set. An exception is thrown if the DataSet contains multiple tables. The OracleCommandBuilder registers itself as a listener for RowUpdating events whenever its DataAdapter property is set. Only one OracleDataAdapter object and one OracleCommandBuilder object can be associated with each other at one time.

To generate INSERT, UPDATE, or DELETE statements, the OracleCommandBuilder uses ExtendedProperties within the DataSet to retrieve a required set of metadata. If the SelectCommand is changed after the metadata is retrieved (for example, after the first update), the RefreshSchema method should be called to update the metadata.

OracleCommandBuilder first looks for the metadata from the ExtendedProperties of the DataSet; if the metadata is not available, OracleCommandBuilder uses the SelectCommand property of the OracleDataAdapter to retrieve the metadata.

Example

The OracleBuilder examples in this section are based on the EMPINFO table which is defined as follows:


CREATE TABLE empInfo (
 empno NUMBER(4) PRIMARY KEY,
 empName VARCHAR2(20) NOT NULL,
 hiredate DATE,
 salary NUMBER(7,2),
 jobDescription Clob,
 byteCodes BLOB
);

The EMPINFO table has the following values:


EMPNO    EMPNAME    HIREDATE    SALARY     JOBDESCRIPTION  BYTECODES 
                                                          (Hex Values)
=====    =======    ========    ======     ==============  ============

    1    KING       01-MAY-81   12345.67   SOFTWARE ENGR   {0x12, 0x34}
    2    SCOTT      01-SEP-75   34567.89   MANAGER         {0x56, 0x78}
    3    BLAKE      01-OCT-90   9999.12    TRANSPORT       {0x23, 0x45}
    4    SMITH      NULL        NULL       NULL             NULL

The following example uses the OracleCommandBuilder object to create the UpdateCommand for the OracleDataAdapter object when OracleDataAdapter.Update() is called.


// C#
public static void BuilderUpdate(string connStr)
{
  string cmdStr = "SELECT EMPNO, EMPNAME, JOBDESCRIPTION FROM EMPINFO";

  //create the adapter with the selectCommand txt and the
  //connection string
  OracleDataAdapter adapter = new OracleDataAdapter(cmdStr, connStr);

  //get the connection from the adapter
  OracleConnection connection = adapter.SelectCommand.Connection;

  //create the builder for the adapter to automatically generate
  //the Command when needed
  OracleCommandBuilder builder = new OracleCommandBuilder(adapter);

  //Create and fill the DataSet using the EMPINFO
  DataSet dataset = new DataSet();
  adapter.Fill(dataset, "EMPINFO");

  //Get the EMPINFO table from the dataset
  DataTable table = dataset.Tables["EMPINFO"];

  //Get the first row from the EMPINFO table
  DataRow row0 = table.Rows[0];

  //update the job description in the first row
  row0["JOBDESCRIPTION"] = "MANAGER";

  //Now update the EMPINFO using the adapter, the job description
  //of 'KING' is changed to 'MANAGER'
  //The OracleCommandBuilder will create the UpdateCommand for the
  //adapter to update the EMPINFO table
  adapter.Update(dataset, "EMPINFO");

}

Requirements

Namespace: Oracle.DataAccess.Client

Assembly: Oracle.DataAccesss.dll

See Also:

OracleCommandBuilder Members

OracleCommandBuilder members are listed in the following tables:

OracleCommandBuilder Constructors

OracleCommandBuilder constructors are listed in Table 4-8.

Table 4-8 OracleCommandBuilder Constructors
Constructor Description

OracleCommandBuilder Constructors

Instantiates a new instance of OracleCommandBuilder class (Overloaded)

OracleCommandBuilder Static Methods

OracleCommandBuilder static methods are listed in Table 4-9.

Table 4-9 OracleCommandBuilder Static Methods  
Methods Description

Equals

Inherited from Object (Overloaded)

OracleCommandBuilder Properties

OracleCommandBuilder properties are listed in Table 4-10.

Table 4-10 OracleCommandBuilder Properties  
Name Description

Container

Inherited from Component

DataAdapter

Indicates the OracleDataAdapter for which the SQL statements are generated

CaseSensitive

Indicates whether or not double quotes are used around Oracle object names when generating SQL statements

Site

Inherited from Component

OracleCommandBuilder Public Methods

OracleCommandBuilder public methods are listed in Table 4-11.

Table 4-11 OracleCommandBuilder Public Methods  
Public Method Description

CreateObjRef

Inherited from MarshalByRefObject

Dispose

Inherited from Component

Equals

Inherited from Object (Overloaded)

GetDeleteCommand

Gets the automatically generated OracleCommand object that has the SQL statement (CommandText) perform deletions on the database

GetHashCode

Inherited from Object

GetInsertCommand

Gets the automatically generated OracleCommand object that has the SQL statement (CommandText) perform insertions on the database

GetLifetimeService

Inherited from MarshalByRefObject

GetType

Inherited from Object

GetUpdateCommand

Gets the automatically generated OracleCommand object that has the SQL statement (CommandText) perform updates on the database

InitializeLifetimeService

Inherited from MarshalByRefObject

RefreshSchema

Refreshes the database schema information used to generate INSERT, UPDATE, or DELETE statements

ToString

Inherited from Object

OracleCommandBuilder Events

OracleCommandBuilder events are listed in Table 4-12.

Table 4-12 OracleCommandBuilder Events
Event Name Description

Disposed

Inherited from Component

OracleCommandBuilder Event Delegates

OracleCommandBuilder event delegates are listed in Table 4-13.

Table 4-13 OracleCommandBuilder Event Delegates  
Event Delegate Name Description

EventHandler

Inherited from Component

See Also:

OracleCommandBuilder Constructors

OracleCommandBuilder constructors create new instances of the OracleCommandBuilder class.

Overload List:

OracleCommandBuilder()

This constructor creates an instance of the OracleCommandBuilder class.

Declaration
// C#
public OracleCommandBuilder();
Remarks

Default constructor.

See Also:

OracleCommandBuilder(OracleDataAdapter)

This constructor creates an instance of the OracleCommandBuilder class and sets the DataAdapter property to the provided OracleDataAdapter object.

Declaration
// C#
public OracleCommandBuilder(OracleDataAdapter da);
Parameters

OracleCommandBuilder Static Methods

OracleCommandBuilder properties are listed in Table 4-14.

Table 4-14 OracleCommandBuilder Static Methods  
Methods Description

Equals

Inherited from Object (Overloaded)

See Also:

OracleCommandBuilder Properties

OracleCommandBuilder properties are listed in Table 4-15.

Table 4-15 OracleCommandBuilder Properties  
Name Description

Container

Inherited from Component

DataAdapter

Indicates the OracleDataAdapter for which the SQL statements are generated

CaseSensitive

Indicates whether or not double quotes are used around Oracle object names when generating SQL statements

Site

Inherited from Component

See Also:

DataAdapter

This property indicates the OracleDataAdapter for which the SQL statements are generated.

Declaration
// C#
OracleDataAdapter DataAdapter{get; set;}
Property Value

OracleDataAdapter

Remarks

Default = null

See Also:

CaseSensitive

This property indicates whether or not double quotes are used around Oracle object names (for example, tables or columns) when generating SQL statements.

Declaration
// C#
bool CaseSensitive {get; set;}
Property Value

A bool that indicates whether or not double quotes are used.

Remarks

Default = false

See Also:

OracleCommandBuilder Public Methods

OracleCommandBuilder public methods are listed in Table 4-16.

Table 4-16 OracleCommandBuilder Public Methods  
Public Method Description

CreateObjRef

Inherited from MarshalByRefObject

Dispose

Inherited from Component

Equals

Inherited from Object (Overloaded)

GetDeleteCommand

Gets the automatically generated OracleCommand object that has the SQL statement (CommandText) perform deletions on the database

GetHashCode

Inherited from Object

GetInsertCommand

Gets the automatically generated OracleCommand object that has the SQL statement (CommandText) perform insertions on the database

GetLifetimeService

Inherited from MarshalByRefObject

GetType

Inherited from Object

GetUpdateCommand

Gets the automatically generated OracleCommand object that has the SQL statement (CommandText) perform updates on the database

InitializeLifetimeService

Inherited from MarshalByRefObject

RefreshSchema

Refreshes the database schema information used to generate INSERT, UPDATE, or DELETE statements

ToString

Inherited from Object

See Also:

GetDeleteCommand

This method gets the automatically generated OracleCommand object that has the SQL statement (CommandText) perform deletions on the database when an application calls Update() on the OracleDataAdapter.

Declaration
// C#
public OracleCommand GetDeleteCommand();
Return Value

An OracleCommand.

Exceptions

ObjectDisposedException - The OracleCommandBuilder object is already disposed.

InvalidOperationException - Either the SelectCommand or the DataAdapter property is null, or the primary key cannot be retrieved from the SelectCommand property of the OracleDataAdapter.

See Also:

GetInsertCommand

This method gets the automatically generated OracleCommand object that has the SQL statement (CommandText) perform insertions on the database when an application calls Update() on the OracleDataAdapter.

Declaration
// C#
public OracleCommand GetInsertCommand();
Return Value

An OracleCommand.

Exceptions

ObjectDisposedException - The OracleCommandBuilder object is already disposed.

InvalidOperationException - Either the SelectCommand or the DataAdapter property is null, or the primary key cannot be retrieved from the SelectCommand property of the OracleDataAdapter.

See Also:

GetUpdateCommand

This method gets the automatically generated OracleCommand object that has the SQL statement (CommandText) perform updates on the database when an application calls Update() on the OracleDataAdapter.

Declaration
// C#
public OracleCommand GetUpdateCommand();
Return Value

An OracleCommand.

Exceptions

ObjectDisposedException - The OracleCommandBuilder object is already disposed.

InvalidOperationException - Either the SelectCommand or the DataAdapter property is null, or the primary key cannot be retrieved from the SelectCommand property of the OracleDataAdapter.

See Also:

RefreshSchema

This method refreshes the database schema information used to generate INSERT, UPDATE, or DELETE statements.

Declaration
// C#
public void RefreshSchema();
Remarks

An application should call RefreshSchema whenever the SelectCommand value of the OracleDataAdapter changes.

See Also:

OracleCommandBuilder Events

OracleCommandBuilder events are listed in Table 4-17.

Table 4-17 OracleCommandBuilder Events
Event Name Description

Disposed

Inherited from Component

See Also:

OracleCommandBuilder Event Delegates

OracleCommandBuilder event delegates are listed in Table 4-18.

Table 4-18 OracleCommandBuilder Event Delegates  
Event Delegate Name Description

EventHandler

Inherited from Component

See Also:


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 2002 Oracle Corporation.

All Rights Reserved.
Go To Table Of Contents
Contents
Go To Index
Index