IDbDataAdapter.DeleteCommand プロパティ

定義

データ セットからレコードを削除するための SQL ステートメントを取得または設定します。

public:
 property System::Data::IDbCommand ^ DeleteCommand { System::Data::IDbCommand ^ get(); void set(System::Data::IDbCommand ^ value); };
public System.Data.IDbCommand DeleteCommand { get; set; }
member this.DeleteCommand : System.Data.IDbCommand with get, set
Public Property DeleteCommand As IDbCommand

プロパティ値

IDbCommandデータ セット内の削除された行のデータ ソース内のレコードを削除するためにUpdate(DataSet)中に使用されます。

次の例では、継承された OleDbDataAdapter クラスのインスタンスを作成し、 SelectCommand プロパティと DeleteCommand プロパティを設定します。 OleDbConnection オブジェクトが既に作成されていることを前提としています。

public static OleDbDataAdapter CreateCustomerAdapter(
    OleDbConnection connection)
{
    OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
    OleDbCommand command;
    OleDbParameter parameter;

    // Create the SelectCommand.
    command = new OleDbCommand("SELECT CustomerID FROM Customers " +
        "WHERE Country = ? AND City = ?", connection);

    command.Parameters.Add("Country", OleDbType.VarChar, 15);
    command.Parameters.Add("City", OleDbType.VarChar, 15);

    dataAdapter.SelectCommand = command;

    // Create the DeleteCommand.
    command = new OleDbCommand(
        "DELETE * FROM Customers WHERE CustomerID = ?",
        connection);

    parameter = command.Parameters.Add(
        "CustomerID", OleDbType.Char, 5, "CustomerID");
    parameter.SourceVersion = DataRowVersion.Original;

    dataAdapter.DeleteCommand = command;

    return dataAdapter;
}
Public Shared Function CreateCustomerAdapter( _
    connection As OleDbConnection) As OleDbDataAdapter 

    Dim dataAdapter As New OleDbDataAdapter()
    Dim command As OleDbCommand
    Dim parameter As OleDbParameter

    ' Create the SelectCommand.
    command = New OleDbCommand("SELECT CustomerID FROM Customers " & _
        "WHERE Country = ? AND City = ?", connection)

    command.Parameters.Add("Country", OleDbType.VarChar, 15)
    command.Parameters.Add("City", OleDbType.VarChar, 15)

    dataAdapter.SelectCommand = command

    ' Create the DeleteCommand.
    command = New OleDbCommand( _
        "DELETE * FROM Customers WHERE CustomerID = ?", _
        connection)

    parameter = command.Parameters.Add( _
        "CustomerID", OleDbType.Char, 5, "CustomerID")
    parameter.SourceVersion = DataRowVersion.Original

    dataAdapter.DeleteCommand = command

    Return dataAdapter
End Function

注釈

Update中に、このプロパティが設定されておらず、主キー情報がDataSetに存在する場合、.NET Framework データ プロバイダーの DeleteCommand プロパティを設定すると、SelectCommandが自動的に生成されます。 その後、設定していない追加のコマンドは、CommandBuilder によって生成されます。 この生成ロジックでは、キー列の情報が DataSetに存在する必要があります。 詳細については、「 CommandBuilders を使用したコマンドの生成」を参照してください。

以前に作成したDeleteCommandIDbCommandが割り当てられている場合、IDbCommandは複製されません。 DeleteCommandは、以前に作成したIDbCommand オブジェクトへの参照を保持します。

適用対象