Đang chuẩn bị liên kết để tải về tài liệu:
Specifying Locking Hints in a SQL Server Database

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

[ Team LiB ] Recipe 6.14 Specifying Locking Hints in a SQL Server Database Problem You need to pessimistically lock rows in an underlying SQL Server database. Solution Use SQL Server locking hints from ADO.NET. The sample code contains three event handlers | Team LiB Recipe 6.14 Specifying Locking Hints in a SQL Server Database Problem You need to pessimistically lock rows in an underlying SQL Server database. Solution Use SQL Server locking hints from ADO.NET. The sample code contains three event handlers Start Tran Button.Click Creates a SQL SELECT statement to retrieve the Orders table from the Northwind database. A locking hint either UPDLOCK or HOLDLOCK is added to the statement as specified. A Connection is opened and a Transaction started on it with an isolation level of ReadCommitted. A DataAdapter is used on the transacted connection to fill a DataTable. A CommandBuilder is created to generate updating logic. The default view of the table is bound to the data grid on the form. Cancel Button.Click Clears the data grid rolls back the transaction and closes the connection. Form.Closing Rolls back the transaction if it exists and closes the connection. The C code is shown in Example 6-39. Example 6-39. File UsingLockingHintsForPessimisticLockingForm.cs Namespaces variables and constants using System using System.Configuration using System.Data using System.Data.SqlClient private SqlConnection conn private SqlTransaction tran H . . . private void startButton_Click object sender System.EventArgs e startButton.Enabled false String sqlText SELECT FROM Orders WITH Add pessimistic locking as specified by user. if updLockRadioButton.Checked sqlText UPDLOCK else if holdLockRadioButton.Checked sqlText HOLDLOCK Create connection. conn new SqlConnection ConfigurationSettings.AppSettings S ql_ConnectString conn.Open Start the transaction. tran conn.BeginTransaction IsolationLevel.ReadCommitted Create the command. SqlCommand cmd new SqlCommand sqlText conn tran Create the DataAdapter and CommandBuilder. SqlDataAdapter da new SqlDataAdapter cmd SqlCommandBuilder cb new SqlCommandBuilder da Fill table using the DataAdapter. DataTable dt new DataTable da.Fill dt Bind the default view of the table to the grid. dataGrid.DataSource

TÀI LIỆU LIÊN QUAN
crossorigin="anonymous">
Đã 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.