tailieunhanh - Specifying Locking Hints in a SQL Server Database

[ Team LiB ] Recipe 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 . The sample code contains three event handlers | Team LiB Recipe 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 . The sample code contains three event handlers Start Tran 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 Clears the data grid rolls back the transaction and closes the connection. Rolls back the transaction if it exists and closes the connection. The C code is shown in Example 6-39. Example 6-39. File Namespaces variables and constants using System using using using private SqlConnection conn private SqlTransaction tran H . . . private void startButton_Click object sender e false String sqlText SELECT FROM Orders WITH Add pessimistic locking as specified by user. if sqlText UPDLOCK else if sqlText HOLDLOCK Create connection. conn new SqlConnection S ql_ConnectString Start the transaction. tran 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 dt Bind the default view of the table to the grid.

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.