Gridview rowupdating event handling
Since we used ad-hoc SQL queries in our original DAL, use this option here as well.
Figure 4: Specify the Data to Retrieve Using an Ad-Hoc SQL Statement (Click to view full-size image) On the following screen, enter the SQL query to use to retrieve the product information. Discontinued = discontinued End Sub _ Public Function Update Product( By Val product Name As String, By Val supplier ID As Nullable(Of Integer), _ By Val category ID As Nullable(Of Integer), By Val quantity Per Unit As String, _ By Val unit Price As Nullable(Of Decimal), By Val units In Stock As Nullable(Of Short), _ By Val units On Order As Nullable(Of Short), By Val reorder Level As Nullable(Of Short), _ By Val discontinued As Boolean, By Val product ID As Integer, _ _ By Val original_product Name As String, _ By Val original_supplier ID As Nullable(Of Integer), _ By Val original_category ID As Nullable(Of Integer), _ By Val original_quantity Per Unit As String, _ By Val original_unit Price As Nullable(Of Decimal), _ By Val original_units In Stock As Nullable(Of Short), _ By Val original_units On Order As Nullable(Of Short), _ By Val original_reorder Level As Nullable(Of Short), _ By Val original_discontinued As Boolean, _ By Val original_product ID As Integer) _ As Boolean ' STEP 1: Read in the current database product information Dim products As _ Northwind Optimistic Concurrency.
Figure 1 graphically depicts this series of events.
Figure 1: When Two Users Simultaneously Update a Record There s Potential for One User 's Changes to Overwrite the Other 's (Click to view full-size image) Similarly, when two users are visiting a page, one user might be in the midst of updating a record when it is deleted by another user.
For web applications that only allow users to view data, or for those that include only a single user who can modify data, there's no threat of two concurrent users accidentally overwriting one another's changes.
Change the method name for the Return a Data Table pattern from Get Data to Get Products, so as to mirror the naming conventions we used in our original DAL. Products Optimistic Concurrency Row = products(0) ' STEP 2: Assign the original values to the product instance Assign All Product Values( _ product, original_product Name, original_supplier ID, _ original_category ID, original_quantity Per Unit, original_unit Price, _ original_units In Stock, original_units On Order, original_reorder Level, _ original_discontinued) ' STEP 3: Accept the changes product.When using optimistic concurrency, the DB direct method overloads that accept Data Rows and Data Tables rather than scalar values) must be changed as well.Rather than extend our existing DAL's Table Adapters to use optimistic concurrency (which would necessitate changing the BLL to accommodate), let's instead create a new Typed Data Set named Business Logic Layer class that has the appropriate modifications to support the optimistic concurrency DAL.For a web application that allows multiple users to edit data, there is the risk that two users may be editing the same data at the same time.In this tutorial we'll implement optimistic concurrency control to handle this risk.