GetDeleteCommand
SqlCommand deleteCommand = CommandBuilder.GetDeleteCommand();
Returns a reference to the automatically generated
Command
object, which deletes data from the data
source when the Update( )
method of the data
adapter is called.
The following example demonstrates how to retrieve the automatically
generated DeleteCommand
,
InsertCommand
, and
UpdateCommand
objects using the
CommandBuilder
:
// connection and select command strings String connString = "Data Source=(local);Integrated security=SSPI;" + "Initial Catalog=Northwind;"; String sqlSelect = "SELECT * FROM Orders"; SqlDataAdapter da=new SqlDataAdapter(sqlSelect, connString); // create the command builder SqlCommandBuilder cb = new SqlCommandBuilder(da); // retrieve the Command objects SqlCommand deleteCommand = cb.GetDeleteCommand(); SqlCommand insertCommand = cb.GetInsertCommand(); SqlCommand updateCommand = cb.GetUpdateCommand();
If the SELECT command that is the basis of the automatically
generated DELETE command is changed, the RefreshSchema( )
method must be called. Otherwise the
GetDeleteCommand( )
method returns a statement for
the previous schema.
Calling one of the GetDeleteCommand( )
,
GetInsertCommand( )
, or GetUpdateCommand( )
methods, or the Update( )
method of
the DataAdapter
generates all delete, insert, and
update command logic.