OracleCommandBuilder Class
Assembly: System.Data.OracleClient (in system.data.oracleclient.dll)
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.MarshalByRefObject
System.ComponentModel.Component
System.Data.Common.DbCommandBuilder
System.Data.OracleClient.OracleCommandBuilder
Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.