Checking for Concurrency Violations

[ Team LiB ] Recipe Checking for Concurrency Violations Problem You need to check for concurrency violations. Solution Use a timestamp column to manage data concurrency violations. | Team LiB Recipe Checking for Concurrency Violations Problem You need to check for concurrency violations. Solution Use a timestamp column to manage data concurrency violations. The schema of table TBL0610 used in this solution is shown in Table 6-12. Table 6-12. TBL0610 schema Column name Data type Length Allow nulls Id int 4 No Fieldl nvarchar 50 Yes rowversion time stamp 8 No The sample code contains four event handlers and two methods Sets up the sample by creating two DataTable objects A and B. For each a DataAdapter is created and a handler is attached to handle the RowUpdated event. The DataAdapter is used to fill the DataTable with both schema and data from table TBL0610 in the database. The update command is defined for the DataAdapter using the timestamp column in the WHERE clause to catch concurrency errors. The first row from both tables is displayed on the form simulating the view of two different simultaneous data users. Checks if the row was inserted or updated. For those rows the current value of the timestamp column is retrieved from the TBL0610 in the database and used to update the row in the DataTable. Update This method copies the specified value for Fieldl from the text box into the DataTable. The DataAdapter is used to update DataTable changes to table TBL0610 in the database. If a DBConcurrencyException is encountered the change to the row is rejected. DisplayRow This method is used to display data from a specified row in DataTable A or B to the corresponding user display on the form. Update Calls the Update method to update changes made to the row in either DataTable A or B. The DisplayRow method is called to update the corresponding row displayed on the form. Refresh Gets the latest values for the row in DataTable A or B from table TBL0610 in the database. The DisplayRow method is called to update the corresponding row displayed on the form. The C code is shown in Example .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
174    387    1    26-04-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.