NET Public Shared Sub Update Product(By Val original_Product ID as Integer, _ By Val original_product Name as String, _ By Val decimal original_unit Price as Decimal, _ By Val original_units In Stock as Integer, _ By Val product Name as String, By Val unit Price as Decimal, _ By Val units In Stock as Integer) ...End Sub // C# public static void Update Product(int original_Product ID, string original_product Name, decimal original_unit Price, int original_units In Stock, string product Name, decimal unit Price, int units In Stock) If you use the Compare All Values approach, it is your responsibility as the DAL developer to take whatever steps are needed to determine if the underlying data has been during the user's edits and, if so, how to resolve the issue.
To help clarify any confusion, let's look at a concrete example.Instead of just using WHERE [Product ID] = @original_Product ID, with optimistic concurrency the WHERE clause would have read: This would prevent an UPDATE from happening if, between the time the user clicked a Grid View row's Edit button and having clicked the Update button, another user had modified that particular row.Like deleting data from a Grid View bound to an Object Data Source, creating an editable Grid View bound to an Object Data Source requires very few changes in the creation of the ASP. Most of the work is required in adding a method to the data access layer class to handle the update.The Grid View allows editing on a row-by-row basis.An editable Grid View contains an additional column with an Edit button in each row.Additionally, the standard Text Box as an editing interface might not be acceptable; we'll also look at an example that replaces the Text Box with a databound Drop Down List.Creating an editable Grid View whose data comes from a Sql Data Source is amazingly easy.Once you have configured a Sql Data Source with an UPDATE statement, creating an editable Grid View is a breeze.Just add a new Grid View to the page and, from its Smart Tag, click the Enable Editing checkbox (see Figure 39).(Recall that we created the Product DAL class back in the The Update Product Method (Visual Basic) Public Class Product DAL ... Close() End Using End Sub End Class The Update Product Method (C#) public class Product DAL As you can see, the Update method, Update Products(), takes in the original_Product ID along with each of the editable columns in the Grid View: product Name, unit Price, and units In Stock.Public Shared Sub Update Product(By Val original_Product ID As Integer, _ By Val product Name As String, By Val unit Price As Decimal, _ By Val units In Stock As Integer) 'Updates the Products table Dim sql As String = "UPDATE Products SET Product Name = " & _ " @Product Name, Unit Price = @Unit Price, Units In Stock = " & _ "@Units In Stock WHERE Product ID = @Product ID" Using my Connection As _ New Sql Connection( _ Configuration Manager. Connection String) Dim my Command As New Sql Command(sql, my Connection) my Command. Add( _ New Sql Parameter("@Product Name", product Name)) my Command. Add(New Sql Parameter("@Unit Price", _ unit Price)) my Command. Add(New Sql Parameter("@Units In Stock", _ units In Stock)) my Command. Add(New Sql Parameter("@Product ID", _ original_Product ID)) my Connection. If you had configured the Object Data Source to Compare All Values you'd need an Update method with a signature like: ' Visual Basic .