Share via


Méthode SqlCeCommandBuilder.GetDeleteCommand

Obtient l'objet SqlCeCommand généré automatiquement qui est requis pour effectuer des suppressions dans la base de données lorsqu'une application appelle Update sur SqlCeDataAdapter.

Espace de noms :  System.Data.SqlServerCe
Assembly :  System.Data.SqlServerCe (en System.Data.SqlServerCe.dll)

Syntaxe

'Déclaration
Public Function GetDeleteCommand As SqlCeCommand
'Utilisation
Dim instance As SqlCeCommandBuilder
Dim returnValue As SqlCeCommand

returnValue = instance.GetDeleteCommand()
public SqlCeCommand GetDeleteCommand()
public:
SqlCeCommand^ GetDeleteCommand()
member GetDeleteCommand : unit -> SqlCeCommand 
public function GetDeleteCommand() : SqlCeCommand

Valeur de retour

Type : System.Data.SqlServerCe.SqlCeCommand
Objet SqlCeCommand généré automatiquement, requis pour effectuer des suppressions.

Notes

Une application peut utiliser la méthode GetDeleteCommand à des fins d'information et de dépannage, car elle retourne l'objet SqlCeCommand à exécuter.

Vous pouvez également utiliser GetDeleteCommand comme base d'une commande modifiée. Par exemple, vous pouvez appeler GetDeleteCommand, modifier l'une de ses propriétés, puis le définir explicitement sur SqlCeDataAdapter.

Lors de la première génération de l'instruction SQL, l'application doit appeler explicitement RefreshSchema() si elle modifie l'instruction SQL de quelque manière que ce soit. Sinon, GetDeleteCommand utilise toujours les informations de l'instruction précédente, qui ne sont peut-être pas correctes. Les instructions SQL sont d'abord générées lorsque l'application appelle Update ou GetDeleteCommand.

Exemples

L'exemple suivant illustre l'appel de la méthode GetDeleteCommand de SqlCeCommandBuilder.

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

    Dim cmd As SqlCeCommand = conn.CreateCommand()
    cmd.CommandText = "SELECT * FROM employees"

    Dim adp As New SqlCeDataAdapter(cmd)

    Dim cb As New SqlCeCommandBuilder()
    cb.DataAdapter = adp

    MessageBox.Show(cb.GetUpdateCommand().CommandText)
    MessageBox.Show(cb.GetInsertCommand().CommandText)
    MessageBox.Show(cb.GetDeleteCommand().CommandText)

    Dim ds As New DataSet("test")
    adp.Fill(ds)

    ' Modify the contents of the DataSet
    '
    ds.Tables(0).Rows(0)("First Name") = "Joe"

    adp.Update(ds)

Catch e1 As Exception
    Console.WriteLine(e1.ToString())
End Try
try
{
    SqlCeConnection conn = new SqlCeConnection("Data Source = MyDatabase.sdf");
    conn.Open();

    SqlCeCommand cmd = conn.CreateCommand();
    cmd.CommandText = "SELECT * FROM employees";

    SqlCeDataAdapter adp = new SqlCeDataAdapter(cmd);

    SqlCeCommandBuilder cb = new SqlCeCommandBuilder();
    cb.DataAdapter = adp;

    MessageBox.Show(cb.GetUpdateCommand().CommandText);
    MessageBox.Show(cb.GetInsertCommand().CommandText);
    MessageBox.Show(cb.GetDeleteCommand().CommandText);

    DataSet ds = new DataSet("test");
    adp.Fill(ds);

    // Modify the contents of the DataSet
    //
    ds.Tables[0].Rows[0]["First Name"] = "Joe";

    adp.Update(ds);

}
catch (Exception e1)
{
    Console.WriteLine(e1.ToString());
}

Voir aussi

Référence

SqlCeCommandBuilder Classe

Surcharge GetDeleteCommand

Espace de noms System.Data.SqlServerCe