SqlDataSourceCommandEventArgs::Command Property
Gets the pending database command.
Assembly: System.Web (in System.Web.dll)
You can handle the Updating, Inserting, or Deleting event to examine and manipulate the properties of the DbCommand before it is run by the SqlDataSource control. The connection to the underlying data source is not yet open when the event handler delegate is called. Therefore, you cannot cancel the database operation by calling the Cancel method on the DbCommand object directly. However, you can cancel the database operation by setting the Cancel property of the SqlDataSourceCommandEventArgs to true.
The following code example demonstrates how to retrieve data from Microsoft SQL Server and display it in a GridView control, and how to use a DetailsView control to see details of a selected row in the GridView and as a form to insert new records.
The data is initially displayed in the GridView control, and the selected row of the GridView is also displayed in the DetailsView. The GridView and DetailsView controls use different data source controls; the one that is associated with the DetailsView has a FilterExpression and FilterParameters that ensure that the selected row of the GridView is displayed.
If you click the automatically-generated insert button of the DetailsView control, the DetailsView shows a different user interface, which is used to insert a new record. The example uses a stored procedure to insert records, and returns the primary key of the inserted row. If you insert a record, the DetailsView automatically populates the InsertParameters collection with values from the bound columns and calls the Insert method. The DetailsView can infer the correct parameters from any BoundField, and a parameter for the TemplateField when the ASP.NET two-way data-binding syntax is used. In this example, an additional parameter is added in the OnInserting event handler to handle the primary key returned by the stored procedure.
Finally, after data is inserted by the DetailsView into the database, the OnInserted event handler is called to handle the Inserted event, the value of the primary key of the inserted row is displayed, and the DataBind method of the GridView control is called explicitly to refresh the data.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.