SqlCeCommandBuilder.GetDeleteCommand Method ()
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 (dans system.data.sqlserverce.dll)
Syntaxe
'Déclaration
Public Function GetDeleteCommand As SqlCeCommand
public SqlCeCommand GetDeleteCommand ()
public:
SqlCeCommand^ GetDeleteCommand ()
public SqlCeCommand GetDeleteCommand ()
public function GetDeleteCommand () : SqlCeCommand
Valeur de retour
Objet SqlCeCommand généré automatiquement, requis pour effectuer des suppressions.
Remarques
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.
Exemple
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());
}
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
SqlCeCommandBuilder Class
SqlCeCommandBuilder Members
System.Data.SqlServerCe Namespace