In this article we will focus on using the Sql Data Source control to insert records into a database.We will look at three examples: using a Sql Data Source to insert a record using values entered by the user through various Text Boxes, Drop Down Lists, and other Web controls on an ASP. This article focuses on the Sql Data Source control; for a detailed look at inserting with the Object Data Source, refer to the "Editing, Inserting, and Deleting" tutorials in my Working with Data in ASP. Let's explore the inserting "action" for the Access Data Source and Sql Data Source controls in more detail.The download at the end of this article includes another Details View example that illusrated adding validation controls and customizing the inserting interface to prompt the user for the new product's category via a drop-down list of available category choices.For more information on customizing the Details View's inserting interface, see Customizing the Data Modification Interface (VB Version) (C# version).We could create a simple Web Form that included Text Boxes, a Drop Down List, and a Check Box control to collect these input fields, along with an "Add Product" Button control that, when clicked, would insert the new product into the database.
In short, you can use the Details View or Form View controls to create an interface for inserting data into the database without having to write a line of code!
NET 2.0 introduced a number of new Web controls designed for accessing and modifying data. NET 2.0's data source and data Web controls make working with data much easier than in previous versions.
These controls allow page developers to declaratively access and modify data without writing any code to perform the data access. These controls allow for a declarative approach to working with data, without needing to write any cumbersome data access code.
Likewise, the parameter values in the statement are assigned based on the parameters in the data source control's Insert Parameters collection, and these parameters can use the same sources as the Select Parameters.
The Access Data Source and Sql Data Source controls, behind the scenes, use the standard ADO. That is, they connect to the database using a The remainder of this article examines three inserting scenarios using the Sql Data Source control: inserting data through a manually-created Web form; inserting data using the Details View control; and retrieving the value of the just-inserted record's IDENTITY column.