OracleDataAdapter.DeleteCommand 属性
定义
获取或设置用于在数据库中删除记录的 SQL 语句或存储过程。Gets or sets an SQL statement or stored procedure used to delete records in the database.
public:
property System::Data::OracleClient::OracleCommand ^ DeleteCommand { System::Data::OracleClient::OracleCommand ^ get(); void set(System::Data::OracleClient::OracleCommand ^ value); };
public System.Data.OracleClient.OracleCommand DeleteCommand { get; set; }
member this.DeleteCommand : System.Data.OracleClient.OracleCommand with get, set
Public Property DeleteCommand As OracleCommand
属性值
OracleCommand,在更新操作过程中使用,用于在数据库中删除与 DataSet 中的已删除行对应的记录。An OracleCommand used during an update operation to delete records in the database that correspond to deleted rows in the DataSet.
示例
下面的示例创建一个 OracleDataAdapter 并设置 SelectCommand 和 DeleteCommand 属性。The following example creates an OracleDataAdapter and sets the SelectCommand and DeleteCommand properties. 假设您已经创建了一个 OracleConnection 对象。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
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 DeleteCommand.
cmd = New OracleCommand("DELETE FROM Dept WHERE DeptNo = :pDeptNo", conn)
parm = cmd.Parameters.Add("pDeptNo", OracleType.Number, 2, "DeptNo")
parm.SourceVersion = DataRowVersion.Original
da.DeleteCommand = cmd
Return da
End Function
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 DeleteCommand.
cmd = new OracleCommand("DELETE FROM Dept WHERE DeptNo = :pDeptNo", conn);
parm = cmd.Parameters.Add("pDeptNo", OracleType.Number, 2, "DeptNo");
parm.SourceVersion = DataRowVersion.Original;
da.DeleteCommand = cmd;
return da;
}
注解
将 DeleteCommand 属性分配给以前创建的时 OracleCommand , OracleCommand 不会克隆。When the DeleteCommand property is assigned to a previously created OracleCommand, the OracleCommand is not cloned. 相反, DeleteCommand 维护对先前创建的的引用 OracleCommand 。Instead, the DeleteCommand maintains a reference to the previously created OracleCommand.
在更新操作过程中,如果 DeleteCommand 未设置,并且主键信息存在于中 DataSet ,则可以使用 OracleCommandBuilder 类来自动生成 DeleteCommand 和将协调到数据库所需的其他命令 DataSet 。During an update operation, if DeleteCommand is not set and primary key information is present in the DataSet, you can use the OracleCommandBuilder class to automatically generate the DeleteCommand, and additional commands needed to reconcile the DataSet to the database. 为此,请设置 SelectCommand 的属性 OracleDataAdapter 。To do this, set the SelectCommand property of the OracleDataAdapter. 生成逻辑还要求中存在键列信息 DataSet 。The generation logic also requires key column information to be present in the DataSet. 有关详细信息,请参阅 通过 Commandbuilder 生成命令。For more information see Generating Commands with CommandBuilders.