SqlCeCommandBuilder.GetDeleteCommand Method

Gets the automatically generated SqlCeCommand object required to perform deletions on the database when an application calls Update on the SqlCeDataAdapter.

Namespace:  System.Data.SqlServerCe
Assembly:  System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)

public SqlCeCommand GetDeleteCommand()

Return Value

Type: System.Data.SqlServerCe.SqlCeCommand
The automatically generated SqlCeCommand object required to perform deletions.

An application can use the GetDeleteCommand method for informational or troubleshooting purposes because it returns the SqlCeCommand object to be executed.

You can also use GetDeleteCommand as the basis of a modified command. For example, you might call GetDeleteCommand, modify one of its properties, and then explicitly set that on the SqlCeDataAdapter.

After the SQL statement is first generated, the application must explicitly call RefreshSchema() if the application changes the SQL statement in any way. Otherwise, the GetDeleteCommand still uses information from the previous statement, and that information might not be correct. The SQL statements are first generated when the application calls either Update or GetDeleteCommand.

The following example shows calling the GetDeleteCommand method of the SqlCeCommandBuilder.

    SqlCeConnection conn = new SqlCeConnection("Data Source = MyDatabase.sdf");

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

    SqlCeDataAdapter adp = new SqlCeDataAdapter(cmd);

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


    DataSet ds = new DataSet("test");

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


catch (Exception e1)