This documentation is archived and is not being maintained.

OracleDataAdapter.UpdateCommand Property

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Gets or sets an SQL statement or stored procedure used to update records in the database.

[Visual Basic]
Public Shadows Property UpdateCommand As OracleCommand
[C#]
public new OracleCommand UpdateCommand {get; set;}
[C++]
public: __property OracleCommand* get_UpdateCommand();
public: __property void set_UpdateCommand(OracleCommand*);
[JScript]
public hide function get UpdateCommand() : OracleCommand;
public function set UpdateCommand(OracleCommand);

Property Value

An OracleCommand used during an update operation to update records in the database that correspond to modified rows in the DataSet.

Remarks

When UpdateCommand is assigned to a previously created OracleCommand, the OracleCommand is not cloned. Instead, the UpdateCommand maintains a reference to the previously created OracleCommand object.

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 Automatically Generated Commands.

Note   If execution of this command returns rows, these rows may be merged with the DataSet depending upon how you set the UpdatedRowSource property of the OracleCommand object.

Example

[Visual Basic, C#, C++] The following example creates an OracleDataAdapter and sets the SelectCommand and UpdateCommand properties. It assumes you have already created an OracleConnection object.

[Visual Basic] 
Public Shared Function CreateCustomerAdapter(conn As OracleConnection) As OracleDataAdapter 
  
  Dim da As OracleDataAdapter = New OracleDataAdapter()
  Dim cmd As OracleCommand
  Dim parm As OracleParameter

  ' 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 UpdateCommand.

  cmd = New OracleCommand("UPDATE Dept SET DeptNo = pDeptNo, DName = pDName " & _
                       "WHERE DeptNo = poldDeptNo", conn)

  cmd.Parameters.Add("pDeptNo", OracleType.Number, 2, "DeptNo")
  cmd.Parameters.Add("pDName", OracleType.NVarChar, 14, "DName")

  parm = cmd.Parameters.Add("poldDeptNo", OracleType.Number, 2, "DeptNo")
  parm.SourceVersion = DataRowVersion.Original

  da.UpdateCommand = cmd

  Return da
End Function

[C#] 
public static OracleDataAdapter CreateCustomerAdapter(OracleConnection conn)
{
  OracleDataAdapter da = new OracleDataAdapter();
  OracleCommand cmd;
  OracleParameter parm;

  // 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 UpdateCommand.

  cmd = new OracleCommand("UPDATE Dept SET DeptNo = pDeptNo, DName = pDName " +
                       "WHERE DeptNo = poldDeptNo", conn);

  cmd.Parameters.Add("pDeptNo", OracleType.Number, 2, "DeptNo");
  cmd.Parameters.Add("pDName", OracleType.NVarChar, 14, "DName");

  parm = cmd.Parameters.Add("poldDeptNo", OracleType.Number, 2, "DeptNo");
  parm.SourceVersion = DataRowVersion.Original;

  da.UpdateCommand = cmd;

  return da;
}

[C++] 
public:
static OracleDataAdapter* CreateCustomerAdapter(OracleConnection* conn)
{
  OracleDataAdapter* da = new OracleDataAdapter();
  OracleCommand* cmd;
  OracleParameter* parm;

  // Create the SelectCommand.

  cmd = new OracleCommand(S"SELECT * FROM Dept " 
                          S"WHERE DName = pDName AND Loc = pLoc", conn);

  cmd->Parameters->Add(S"pDName", OracleType::NVarChar, 14);
  cmd->Parameters->Add(S"pLoc", OracleType::NVarChar, 13);

  da->SelectCommand = cmd;

  // Create the UpdateCommand.

  cmd = new OracleCommand(S"UPDATE Dept SET DeptNo = pDeptNo, DName = pDName " 
                          S"WHERE DeptNo = poldDeptNo", conn);

  cmd->Parameters->Add(S"pDeptNo", OracleType::Number, 2, S"DeptNo");
  cmd->Parameters->Add(S"pDName", OracleType::NVarChar, 14, S"DName");

  parm = cmd->Parameters->Add(S"poldDeptNo", OracleType::Number, 2, S"DeptNo");
  parm->SourceVersion = DataRowVersion::Original;

  da->UpdateCommand = cmd;

  return da;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

OracleDataAdapter Class | OracleDataAdapter Members | System.Data.OracleClient Namespace | DeleteCommand | InsertCommand | SelectCommand

Show: