DbDataAdapter.DeleteCommand Property

Definition

Gets or sets a command for deleting records from the data set.

C#
[System.ComponentModel.Browsable(false)]
public System.Data.Common.DbCommand? DeleteCommand { get; set; }
C#
[System.ComponentModel.Browsable(false)]
public System.Data.Common.DbCommand DeleteCommand { get; set; }

Property Value

An IDbCommand used during Update(DataSet) to delete records in the data source for deleted rows in the data set.

Attributes

Examples

The following example creates the derived class OleDbDataAdapter and sets some of its properties.

C#
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;
}

Remarks

During Update, if this property is not set and primary key information is present in the DataSet, the DeleteCommand is automatically generated.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also