Start Updating database using gridview

Updating database using gridview

Likewise, the parameter values in the statement are assigned based on the parameters in the data source control's Delete Parameters collection, and these parameters can use the same sources as the Select Parameters.

In addition to deleting the product, we also need to rebind the data to the Drop Down List (so that it is updated to no longer include the just-deleted product). Replace("'", "\'")), True) 'Rebind the data to the Drop Down List so that the just-deleted product no longer appears Product List.

Also, it would be nice to display some sort of confirmation message to the user upon deletion. Data Bind() End Sub A number of new data Web controls were introduced with ASP. These include the Grid View, Details View, and Form View, among others.

This business logic could be enforced in one of two ways: by programmatically hiding or disabling the Delete buttons for those records that cannot be deleted; or by programmatically checking the business rules when the Delete button is clicked and cancelling the delete if necessary. Let's look at how to implement cancelling a delete from the Sql Data Source control's Protected Sub Products Data Source_Deleting(By Val sender As Object, By Val e As System. In this article we looked at how to use the Sql Data Source to delete data from a database.

For information on adding a client-side confirmation messagebox to a Grid View's Delete buttons, see Adding Client-Side Confirmation When Deleting (VB Version) (C# version). For example, we might include a Grid View that includes a Delete button for each row, although there may be certain business rules that prohibit certain records from being deleted. Deleting 'Determine if the product being deleted has a unit price $50 Dim product ID As Integer = Convert. 'Let's use data access code Dim my Connection As New Sql Connection(Configuration Manager. Connection String) Const str Sql As String = "SELECT Unit Price FROM Products WHERE Product ID = @Product ID" Dim my Command As New Sql Command(str Sql, my Connection) my Command. Add With Value("@Product ID", product ID) my Connection. The following screen shot shows what happens when attempting to delete "Carnarvon Tigers," a product whose price exceeds $50.00.

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.

In future installments of this article series we will take a similar in-depth look at updating. This article is one in a series of articles on ASP.

I am trying to update the database from my web form grid.