OracleDataAdapter.InsertCommand Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets an SQL statement or stored procedure used to insert new records into the database.
public:
property System::Data::OracleClient::OracleCommand ^ InsertCommand { System::Data::OracleClient::OracleCommand ^ get(); void set(System::Data::OracleClient::OracleCommand ^ value); };
public System.Data.OracleClient.OracleCommand InsertCommand { get; set; }
member this.InsertCommand : System.Data.OracleClient.OracleCommand with get, set
Public Property InsertCommand As OracleCommand
Property Value
An OracleCommand used during an update operation to insert records in the database that correspond to new rows in the DataSet.
Examples
The following example creates an OracleDataAdapter and sets the SelectCommand and InsertCommand properties. It assumes you have already created an OracleConnection object.
Public Shared Function CreateCustomerAdapter(conn As OracleConnection) As OracleDataAdapter
Dim da As OracleDataAdapter = New OracleDataAdapter()
Dim cmd As OracleCommand
' Create the SelectCommand.
cmd = New OracleCommand("SELECT * FROM Dept " & _
"WHERE DName = :pDName AND Loc = :pLoc", conn)
cmd.Parameters.Add("pDName", OracleType.NVarChar, 14)
cmd.Parameters.Add("pLoc", OracleType.NVarChar, 13)
da.SelectCommand = cmd
' Create the InsertCommand.
cmd = New OracleCommand("INSERT INTO Dept (DeptNo, DName) " & _
"VALUES (:pDeptNo, :pDName)", conn)
cmd.Parameters.Add("pDeptNo", OracleType.Number, 2, "DeptNo")
cmd.Parameters.Add("pDName", OracleType.NVarChar, 14, "DName")
da.InsertCommand = cmd
Return da
End Function
public static OracleDataAdapter CreateCustomerAdapter(OracleConnection conn)
{
OracleDataAdapter da = new OracleDataAdapter();
OracleCommand cmd;
// Create the SelectCommand.
cmd = new OracleCommand("SELECT * FROM Dept " +
"WHERE DName = :pDName AND Loc = :pLoc", conn);
cmd.Parameters.Add("pDName", OracleType.NVarChar, 14);
cmd.Parameters.Add("pLoc", OracleType.NVarChar, 13);
da.SelectCommand = cmd;
// Create the InsertCommand.
cmd = new OracleCommand("INSERT INTO Dept (DeptNo, DName) " +
"VALUES (:pDeptNo, :pDName)", conn);
cmd.Parameters.Add("pDeptNo", OracleType.Number, 2, "DeptNo");
cmd.Parameters.Add("pDName", OracleType.NVarChar, 14, "DName");
da.InsertCommand = cmd;
return da;
}
Remarks
When the InsertCommand property is assigned to a previously created OracleCommand object, the OracleCommand is not cloned. Instead, InsertCommand maintains a reference to the previously created OracleCommand.
During an update operation, if InsertCommand is not set and primary key information is present in the DataSet, you can use the OracleCommandBuilder class to automatically generate InsertCommand, and additional commands needed to reconcile the DataSet to the database. To do this, set the SelectCommand property of the OracleDataAdapter. The generation logic also requires key column information to be present in the DataSet. For more information see Generating Commands with CommandBuilders.
Note
If execution of this command returns rows, these rows may be added to the DataSet depending upon how you set the UpdatedRowSource property of the OracleCommand object.
When you update a column with the LONG RAW
data type, an exception is thrown when you enter a value of NULL
in the column. The Oracle LONG RAW
data type is a deprecated type in Oracle version 8.0. To avoid this error, use the BLOB
data type instead of LONG RAW
.