SqlCeDataAdapter.DeleteCommand Property

Obtient ou définit une instruction SQL permettant de supprimer les enregistrements du groupe de données.

Espace de noms: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (dans system.data.sqlserverce.dll)

Syntaxe

'Déclaration
Public Property DeleteCommand As SqlCeCommand
public SqlCeCommand DeleteCommand { get; set; }
public:
property SqlCeCommand^ DeleteCommand {
    SqlCeCommand^ get ();
    void set (SqlCeCommand^ value);
}
/** @property */
public SqlCeCommand get_DeleteCommand ()

/** @property */
public void set_DeleteCommand (SqlCeCommand value)
public function get DeleteCommand () : SqlCeCommand

public function set DeleteCommand (value : SqlCeCommand)

Valeur de propriété

SqlCeCommand utilisé pendant Update pour supprimer de la source de données les enregistrements qui correspondent aux lignes supprimées dans DataSet.

Remarques

Pendant un appel à Update, si cette propriété n'est pas définie et si les informations de clé primaire sont présentes dans DataSet, DeleteCommand peut être généré automatiquement à condition que la propriété SelectCommand soit définie et que vous utilisiez SqlCeCommandBuilder. Toutes les commandes supplémentaires que vous ne définissez pas sont par la suite générées par SqlCeCommandBuilder. Cette logique de génération exige la présence des informations de colonne clé dans le DataSet.

Si la propriété DeleteCommand est assignée à un SqlCeCommand préalablement créé, SqlCeCommand n'est pas cloné. DeleteCommand conserve une référence à l'objet SqlCeCommand préalablement créé.

Exemple

L'exemple suivant crée un SqlCeDataAdapter et définit certaines de ses propriétés.

Dim cmd As SqlCeCommand = Nothing
Dim adp As SqlCeDataAdapter = Nothing

Try
    adp = New SqlCeDataAdapter()
    Dim conn As New SqlCeConnection("Data Source = MyDatabase.sdf")

    ' Create the SelectCommand
    '
    cmd = conn.CreateCommand()
    cmd.CommandText = "SELECT * FROM Orders WHERE [Ship Country] = @country AND [Ship City] = @city"
    cmd.Parameters.Add("@country", SqlDbType.NVarChar, 15)
    cmd.Parameters.Add("@city", SqlDbType.NVarChar, 15)

    cmd.Parameters("@country").Value = "UK"
    cmd.Parameters("@city").Value = "London"

    adp.SelectCommand = cmd

    ' Create the DeleteCommand
    '
    cmd = conn.CreateCommand()
    cmd.CommandText = "DELETE FROM Orders WHERE [Order ID] = @orderID"

    Dim p As SqlCeParameter = cmd.Parameters.Add("@orderID", SqlDbType.NChar, 5, "Order ID")
    p.SourceVersion = DataRowVersion.Original

    adp.DeleteCommand = cmd

    ' Populate the dataset with the results from the SELECT statement
    '
    Dim ds As New DataSet()
    adp.Fill(ds)

    ' Modify the dataset
    '
    MessageBox.Show("Number of rows: " & ds.Tables(0).Rows.Count)

    ' Delete some rows
    '
    ds.Tables(0).Rows(3).Delete()
    ds.Tables(0).Rows(4).Delete()

    ' This will execute two DELETE statements 
    '
    adp.Update(ds.Tables(0))
Catch e As Exception
    MessageBox.Show(e.Message)
Finally
    If Not Nothing Is adp.SelectCommand Then
        adp.SelectCommand.Dispose()
    End If
    If Not Nothing Is adp.DeleteCommand Then
        adp.DeleteCommand.Dispose()
    End If
End Try
SqlCeCommand cmd = null;
SqlCeDataAdapter adp = null;

try
{
    adp = new SqlCeDataAdapter();
    SqlCeConnection conn = new SqlCeConnection("Data Source = MyDatabase.sdf");

    // Create the SelectCommand
    //
    cmd = conn.CreateCommand();
    cmd.CommandText = "SELECT * FROM Orders WHERE [Ship Country] = @country AND [Ship City] = @city";
    cmd.Parameters.Add("@country", SqlDbType.NVarChar, 15);
    cmd.Parameters.Add("@city", SqlDbType.NVarChar, 15);

    cmd.Parameters["@country"].Value = "UK";
    cmd.Parameters["@city"].Value = "London";

    adp.SelectCommand = cmd;

    // Create the DeleteCommand
    //
    cmd = conn.CreateCommand();
    cmd.CommandText = "DELETE FROM Orders WHERE [Order ID] = @orderID";

    SqlCeParameter p = cmd.Parameters.Add("@orderID", SqlDbType.NChar, 5, "Order ID");
    p.SourceVersion = DataRowVersion.Original;

    adp.DeleteCommand = cmd;

    // Populate the dataset with the results from the SELECT statement
    //
    DataSet ds = new DataSet();
    adp.Fill(ds);

    // Modify the dataset
    //
    MessageBox.Show("Number of rows: " + ds.Tables[0].Rows.Count);

    // Delete some rows
    //
    ds.Tables[0].Rows[3].Delete();
    ds.Tables[0].Rows[4].Delete();

    // This will execute two DELETE statements 
    //
    adp.Update(ds.Tables[0]);
}
catch (Exception e)
{
    MessageBox.Show(e.Message);
}
finally
{
    if (null != adp.SelectCommand) adp.SelectCommand.Dispose();
    if (null != adp.DeleteCommand) adp.DeleteCommand.Dispose();
}

Sécurité des threads

Tout membre statique public (Partagé dans Microsoft Visual Basic) de ce type sont thread-safe. Tous les membres de l'instance ne sont pas garantis comme sûrs.

Plateformes

Plateformes de développement

Windows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0
Informations sur la version
.NET Framework et NET Compact Framework
Pris en charge dans 3.5
.NET Framework
Pris en charge dans 3.0
.NET Compact Framework et .Net Framework
Pris en charge dans 2.0

Voir aussi

Référence

SqlCeDataAdapter Class
SqlCeDataAdapter Members
System.Data.SqlServerCe Namespace
InsertCommand
SelectCommand
UpdateCommand