获取或设置用来删除数据库中的记录的 SQL 语句或存储过程。
[Visual Basic]
Public Property DeleteCommand As DB2Command
[C#]
public new DB2Command
DeleteCommand {get; set;}
[C++]
public: __property DB2Command
* get_DeleteCommand();
public: __property void set_DeleteCommand(DB2Command
*);
[JScript]
public function get DeleteCommand() : DB2Command
;
public function set DeleteCommand(DB2Command
);
在更新操作期间用来删除数据库中与 DataSet 中已删除行相对应的记录的 DB2®Command。
将 DeleteCommand 属性指定给先前创建的 DB2Command 时,将不克隆该 DB2Command。相反,DeleteCommand 将保持对先前创建的 DB2Command 的引用。
在更新操作期间,如果未设置 DeleteCommand 并且 DataSet 中包含主键信息,那么可以使用 DB2CommandBuilder 类来自动生成 DeleteCommand 和使 DataSet 与数据库相一致所需的其他命令。为此,请设置 DB2DataAdapter 的 SelectCommand 属性。生成逻辑还要求 DataSet 中存在键列信息。有关更多信息,请参阅 Microsoft(R) .NET Framework SDK 文档中的“自动生成的命令”。
[Visual Basic, C#] 以下示例将创建 DB2DataAdapter 并设置它的某些属性。
[Visual Basic]
Public Sub CreateDB2DataAdapter()
Dim mySelectText As String = _
"SELECT * FROM STAFF ORDER BY ID"
Dim myConnString As String = _
"DATABASE=SAMPLE;"
Dim myDataAdapter As New DB2DataAdapter(mySelectText, myConnString)
Dim myDataAdapter.DeleteCommand = New DB2Command(
"DELETE FROM STAFF WHERE JOB ='Sales' ", myConnString)
End Sub
[C#]
public void CreateDB2DataAdapter () {
string mySelectText = "SELECT * FROM STAFF ORDER BY ID";
string myConnString = "DATABASE=SAMPLE;";
DB2DataAdapter myDataAdapter = new DB2DataAdapter(mySelectText,myConnString);
myDataAdapter.DeleteCommand = New DB2Command(
"DELETE FROM STAFF WHERE JOB ='Sales' ", myConnString);
}