Export (0) Print
Expand All

OracleCommandBuilder Class

Automatically generates single-table commands used to reconcile changes made to a DataSet with the associated database. This class cannot be inherited.

Namespace: System.Data.OracleClient
Assembly: System.Data.OracleClient (in system.data.oracleclient.dll)

public sealed class OracleCommandBuilder : DbCommandBuilder
public final class OracleCommandBuilder extends DbCommandBuilder
public final class OracleCommandBuilder extends DbCommandBuilder

The OracleDataAdapter does not automatically generate the SQL statements required to reconcile changes made to a DataSet associated with the database. However, you can create an OracleCommandBuilder object that generates SQL statements for single-table updates by setting the SelectCommand property of the OracleDataAdapter. Then, the OracleCommandBuilder generates any additional SQL statements that you do not set.

The relationship between an OracleDataAdapter and its corresponding OracleCommandBuilder is always one-to-one. To create this correspondence, you set the OracleDataAdapter property of the OracleCommandBuilder object. This causes the OracleCommandBuilder to register itself as a listener, which produces the output of RowUpdating events that affect the DataSet.

To generate INSERT, UPDATE, or DELETE statements, the OracleCommandBuilder uses the SelectCommand property to retrieve a required set of metadata.

The OracleCommandBuilder also uses the Connection, and Transaction properties referenced by the SelectCommand.

If you call Dispose, the OracleCommandBuilder is disassociated from the OracleDataAdapter, and the generated commands are no longer used.

The following example uses OracleCommand, along with OracleDataAdapter and OracleConnection, to select rows from a database. 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 database table. The example then creates an OracleCommandBuilder.

[Visual Basic]

Private Function SelectOracleRows(connection As String, queryString As String, tableName As String) As DataSet

   Dim connection As New OracleConnection(connection)
   Dim dataAdapter As New OracleDataAdapter()
   Dim dataSet As DataSet = New DataSet

   dataAdapter.SelectCommand = New OracleCommand(queryString, connection)

   Dim cmdBuilder As OracleCommandBuilder = New OracleCommandBuilder(dataAdapter)

   connection.Open()
   dataAdapter.Fill(dataSet, tableName)
      ' Code to modify data in DataSet here 
      ' Without the OracleCommandBuilder this line would fail.
   dataAdapter.Update(dataSet, tableName)
   connection.Close()
End Function

[C#]

public static DataSet SelectOracleSrvRows(string myConnection, string mySelectQuery, string myTableName)
{
   OracleConnection myConn = new OracleConnection(myConnection);
   OracleDataAdapter myDataAdapter = new OracleDataAdapter();
   myDataAdapter.SelectCommand = new OracleCommand(mySelectQuery, myConn);
   OracleCommandBuilder cb = new OracleCommandBuilder(myDataAdapter);

   myConn.Open();
   DataSet ds = new DataSet();
   myDataAdapter.Fill(ds, myTableName);

   //Code to modify data in DataSet goes here...

   //Without the OracleCommandBuilder this line would fail.
   myDataAdapter.Update(ds, myTableName);
   myConn.Close();
   return ds;

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Data.Common.DbCommandBuilder
        System.Data.OracleClient.OracleCommandBuilder

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1

Community Additions

ADD
Show:
© 2014 Microsoft