SqlDataSource.Insert Method ()
Assembly: System.Web (in System.Web.dll)
Before the insert operation is performed, the OnInserting method is called to raise the Inserting event. You can handle this event to examine the values of the parameters and to perform any preprocessing before the operation. To perform an insert operation, the SqlDataSourceView object builds an DbCommand object using the InsertCommand text and any associated InsertParameters properties, and then executes the DbCommand object against the underlying database.
The SqlDataSource control is associated with a data-bound control, the data-bound control automatically calls the Insert method.method is provided for programmatic access to the Insert method. If the
The following code example demonstrates how to insert data into a database using the SqlDataSource control and a simple Web Forms page. The current data in the Data table is displayed in the DropDownList control. You can add new records by entering values in the TextBox controls, and then clicking the Insert button. When the Insert button is clicked, the specified values are inserted into the database, and then the DropDownList is refreshed.
This example includes a text box that accepts user input, which is a potential security threat and values are inserted into parameters without validation, which is also a potential security threat. Use the Inserting event to validate parameter values before executing the query. For more information, see Script Exploits Overview.
This example shows how to use declarative syntax for data access. For information about how to access data by using code instead of markup, see Accessing Data in Visual Studio.
Available since 2.0