IDbDataAdapter.DeleteCommand Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient ou définit une instruction SQL pour supprimer des enregistrements du jeu de données.
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
Valeur de propriété
Utilisé IDbCommand pendant Update(DataSet) la suppression d’enregistrements dans la source de données pour les lignes supprimées dans le jeu de données.
Exemples
L’exemple suivant crée une instance de la classe héritée OleDbDataAdapter et définit les propriétés et SelectCommand les DeleteCommand propriétés. Il part du principe que vous avez déjà créé un OleDbConnection objet.
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
Remarques
Pendant Update, si cette propriété n’est pas définie et que les informations de clé primaire sont présentes dans le DataSet, elles DeleteCommand peuvent être générées automatiquement si vous définissez la SelectCommand propriété d’un fournisseur de données .NET Framework. Ensuite, toutes les commandes supplémentaires que vous ne définissez pas sont générées par CommandBuilder. Cette logique de génération nécessite que les informations de colonne clés soient présentes dans le DataSet. Pour plus d’informations, consultez Génération de commandes avec CommandBuilders.
Lorsqu’il DeleteCommand est affecté à un précédemment créé IDbCommand, il IDbCommand n’est pas cloné. Conserve DeleteCommand une référence à l’objet créé IDbCommand précédemment.