This article is one in a series of articles on ASP. The articles we have explored in the series thus far have focused on understanding the core concepts of the data source controls and how to retrieve data from the database.In addition to retrieving data, the data source controls can also insert, update, and delete data.
The Details View and Form View controls can also be configured to display an inserting interface.
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!
Add Product And Return New Product IDValue ( @Product Name nvarchar(40), @Category ID int, @Unit Price money, @Discontinued bit, ) AS -- Insert the record into the database INSERT INTO Products(Product Name, Category ID, Unit Price, Discontinued) VALUES (@Product Name, @Category ID, @Unit Price, @Discontinued) -- Read the just-inserted Product ID into @New Product ID SET @New Product ID = SCOPE_IDENTITY() Protected Sub Add Product Data Source_Inserted(By Val sender As Object, By Val e As System. In future installments of this article series we will take a similar in-depth look at updating and deleting. This article is one in a series of articles on ASP.
This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. By joining today you can post your own programming questions, respond to other developers questions, and eliminate the ads that are displayed to guests. When I click on the "Insert" link after filling in the Text Boxes from a Details View control, I would like my Grid View display to now include everything I had plus the new insertion "row" (after insertion, "re-visit" the specifiic table). Click the button below this post to show your appreciation!
These values start at some seed (usually 1) and increment by some specified amount with each new record (usually incremented by 1). Sql Data Source Status Event Args) Handles Add Product Data Source. We worked through three examples: inserting using a manually-created Web Form; inserting from a Details View control; and retrieving the column value of the just-inserted record. NET 2.0 introduced a number of new Web controls designed for accessing and modifying data.
Therefore, if you add three new records to the table, the ALTER PROCEDURE dbo. Inserted 'Read the value of the @New Product ID OUTPUT parameter Dim new Product ID As Integer = Convert. In all three cases, the Sql Data Source control encapsulates many of the data access tasks, such as connecting to the database, creating the command object, and executing the parameterized query. These controls allow page developers to declaratively access and modify data without writing any code to perform the data access.
The Details View and Form View controls have a lot in common - they both display one record at a time and can display interfaces for inserting and updating data.
The difference between the two is that the Details View control is composed of Data Fields (Bound Fields, Check Box Fields, Template Fields, and so on), just like the Grid View. The Form View, on the other hand, uses templates instead of Data Fields; consequently, it allows for a much more flexible layout of its display, inserting, and updating interfaces.
In this article we will focus on using the Sql Data Source control to insert records into a database.