| Oracle® Data Provider for .NET Developer's Guide Release 9.2.0.4 Part Number B10961-01 |
|
Oracle.DataAccess.Client Namespace, 3 of 30
An OracleCommandBuilder object provides automatic SQL generation for the OracleDataAdapter when updates are made to the database.
Object
MarshalByRefObject
Component
OracleCommandBuilder
// C# public sealed class OracleCommandBuilder : Component
All public static methods are thread-safe, although instance methods do not guarantee thread safety.
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.
The OracleCommandBuilder 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"); }
Namespace: Oracle.DataAccess.Client
Assembly: Oracle.DataAccess.dll
OracleCommandBuilder members are listed in the following tables:
OracleCommandBuilder constructors are listed in Table 4-8.
| Constructor | Description |
|---|---|
|
Instantiates a new instance of OracleCommandBuilder class (Overloaded) |
OracleCommandBuilder static methods are listed in Table 4-9.
| Methods | Description |
|---|---|
|
|
Inherited from |
OracleCommandBuilder properties are listed in Table 4-10.
OracleCommandBuilder public methods are listed in Table 4-11.
OracleCommandBuilder events are listed in Table 4-12.
| Event Name | Description |
|---|---|
|
|
Inherited from |
OracleCommandBuilder event delegates are listed in Table 4-13.
| Event Delegate Name | Description |
|---|---|
|
|
Inherited from |
OracleCommandBuilder constructors create new instances of the OracleCommandBuilder class.
This constructor creates an instance of the OracleCommandBuilder class.
This constructor creates an instance of the OracleCommandBuilder class and sets the DataAdapter property to the provided OracleDataAdapter object.
This constructor creates an instance of the OracleCommandBuilder class.
// C# public OracleCommandBuilder();
Default constructor.
This constructor creates an instance of the OracleCommandBuilder class and sets the DataAdapter property to the provided OracleDataAdapter object.
// C# public OracleCommandBuilder(OracleDataAdapter da);
OracleCommandBuilder properties are listed in Table 4-14.
| Methods | Description |
|---|---|
|
|
Inherited from |
OracleCommandBuilder properties are listed in Table 4-15.
This property indicates the OracleDataAdapter for which the SQL statements are generated.
// C# OracleDataAdapter DataAdapter{get; set;}
OracleDataAdapter
Default = null
This property indicates whether or not double quotes are used around Oracle object names (for example, tables or columns) when generating SQL statements.
// C# bool CaseSensitive {get; set;}
A bool that indicates whether or not double quotes are used.
Default = false
OracleCommandBuilder public methods are listed in Table 4-16.
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.
// C# public OracleCommand GetDeleteCommand();
An OracleCommand.
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.
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.
// C# public OracleCommand GetInsertCommand();
An OracleCommand.
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.
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.
// C# public OracleCommand GetUpdateCommand();
An OracleCommand.
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.
This method refreshes the database schema information used to generate INSERT, UPDATE, or DELETE statements.
// C# public void RefreshSchema();
An application should call RefreshSchema whenever the SelectCommand value of the OracleDataAdapter changes.
OracleCommandBuilder events are listed in Table 4-17.
| Event Name | Description |
|---|---|
|
|
Inherited from |
OracleCommandBuilder event delegates are listed in Table 4-18.
| Event Delegate Name | Description |
|---|---|
|
|
Inherited from |
|
|
![]() Copyright © 2002, 2003 Oracle Corporation. All Rights Reserved. |
|