IDbDataAdapter.DeleteCommand Propriedade

Definição

Obtém ou define uma instrução SQL para excluir registros do conjunto de dados.Gets or sets an SQL statement for deleting records from the data set.

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

Valor da propriedade

IDbCommand

Um IDbCommand usado durante Update(DataSet) para excluir registros na fonte de dados para linhas excluídas no conjunto de dados.An IDbCommand used during Update(DataSet) to delete records in the data source for deleted rows in the data set.

Exemplos

O exemplo a seguir cria uma instância da classe herdada OleDbDataAdapter e define as SelectCommand DeleteCommand Propriedades e.The following example creates an instance of the inherited OleDbDataAdapter class, and sets the SelectCommand and DeleteCommand properties. Ele pressupõe que você já criou um OleDbConnection objeto.It assumes you have already created an OleDbConnection object.

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

Comentários

Durante Update , se essa propriedade não for definida e as informações de chave primária estiverem presentes no DataSet , o DeleteCommand poderá ser gerado automaticamente se você definir a SelectCommand propriedade de um provedor de dados de .NET Framework.During Update, if this property is not set and primary key information is present in the DataSet, the DeleteCommand can be generated automatically if you set the SelectCommand property of a .NET Framework data provider. Em seguida, os comandos adicionais que você não definir serão gerados pelo CommandBuilder.Then, any additional commands that you do not set are generated by the CommandBuilder. Esta lógica de geração requer que as informações da coluna principal estejam presente no DataSet.This generation logic requires key column information to be present in the DataSet. Para obter mais informações, consulte gerando comandos com CommandBuilders.For more information see Generating Commands with CommandBuilders.

Quando DeleteCommand é atribuído a um criado anteriormente IDbCommand , o IDbCommand não é clonado.When DeleteCommand is assigned to a previously created IDbCommand, the IDbCommand is not cloned. O DeleteCommand mantém uma referência ao objeto criado anteriormente IDbCommand .The DeleteCommand maintains a reference to the previously created IDbCommand object.

Aplica-se a