SqlDataAdapter.DeleteCommand Property


Gets or sets a Transact-SQL statement or stored procedure to delete records from the data set.

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

member DeleteCommand : SqlCommand with get, set

Property Value

Type: System.Data.SqlClient.SqlCommand

A SqlCommand used during Update to delete records in the database that correspond to deleted rows in the DataSet.

During Update, if this property is not set and primary key information is present in the DataSet, the DeleteCommand can be generated automatically if you set the SelectCommand property and use the SqlCommandBuilder. Then, any additional commands that you do not set are generated by the SqlCommandBuilder. This generation logic requires key column information to be present in the DataSet. For more information, see Generating Commands with CommandBuilders.

When DeleteCommand is assigned to a previously created SqlCommand, the SqlCommand is not cloned. The DeleteCommand maintains a reference to the previously created SqlCommand object.

For every column that you propagate to the data source on Update, a parameter should be added to the InsertCommand, UpdateCommand, or DeleteCommand. The SourceColumn property of the parameter should be set to the name of the column. This indicates that the value of the parameter is not set manually, but is taken from the particular column in the currently processed row.

The following example creates a SqlDataAdapter and sets the SelectCommand, InsertCommand, UpdateCommand, and DeleteCommand properties. It assumes you have already created a SqlConnection object.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top