Export (0) Print
Expand All

SqlDataSource.DeleteCommand Property

Gets or sets the SQL string that the SqlDataSource control uses to delete data from the underlying database.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

member DeleteCommand : string with get, set
<asp:SqlDataSource DeleteCommand="String" />

Property Value

Type: System.String
An SQL string that the SqlDataSource uses to delete data.

The DeleteCommand represents an SQL query or the name of a stored procedure, and is used by the Delete method.

Because different database products use different varieties of SQL, the syntax of the SQL string depends on the current ADO.NET provider being used, which is identified by the ProviderName property. If the SQL string is a parameterized query or command, the syntax of the parameter also depends on the ADO.NET provider being used. For example, if the provider is the System.Data.SqlClient, which is the default provider for the SqlDataSource class, the syntax of the parameter is '@parameterName'. However, if the provider is set to the System.Data.Odbc or System.Data.OleDb, the placeholder of the parameter is '?'. For more information about parameterized SQL queries and commands, see Using Parameters with the SqlDataSource Control.

The DeleteCommand property can be an SQL string or the name of a stored procedure, if the database supports stored procedures.

The DeleteCommand property delegates to the DeleteCommand property of the SqlDataSourceView object that is associated with the SqlDataSource control.

Security noteSecurity Note

For security purposes, the DeleteCommand property is not stored in view state. Because it is possible to decode the contents of view state on the client, storing sensitive information about the database structure in view state could result in an information disclosure vulnerability.

The following code example demonstrates how to set the DeleteCommand text to delete an order from the Northwind database Orders table. Data is retrieved from the Orders table and displayed in a GridView control. The GridView renders a Delete button automatically when the AutoGenerateDeleteButton property is set to true. Additionally, when the Delete button is clicked, the GridView control automatically populates the DeleteParameters collection and calls the Delete method. Finally, because this code example deletes data, an event handler is added to attempt to back up the database to disk before the Delete operation is performed.

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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft