tailieunhanh - Using a Transaction with a DataAdapter

[ Team LiB ] Recipe Using a Transaction with a DataAdapter Problem You need to use a transaction when updating a data source using a DataAdapter. Solution Associate a Transaction with the appropriate Command object from the DataAdapter. The sample code contains three event handlers | Team LiB Recipe Using a Transaction with a DataAdapter Problem You need to use a transaction when updating a data source using a DataAdapter. Solution Associate a Transaction with the appropriate Command object from the DataAdapter. The sample code contains three event handlers Sets up the sample by using a DataAdapter to load a DataTable with the Orders table from the Northwind database. A CommandBuilder is used to generate the updating logic. The default view of the DataTable is bound to a data grid on the form. Update Creates a new Transaction object on the Connection of the SelectCommand of the DataAdapter. The Transaction is associated with the Connection objects for the update commands generated for the DataAdapter by the CommandBuilder. The Update method of the DataAdapter is called to update DataTable changes to the Orders table. If no errors are encountered the transaction is committed otherwise all changes made are rolled back. Refresh Clears and reloads the Orders DataTable. The C code is shown in Example 6-7. Example 6-7. File Namespaces variables and constants using System using using using using private const String ORDERS_TABLE Orders private DataTable dt private SqlDataAdapter da private SqlCommandBuilder cb . . . private void TransactionDataAdapterForm_Load object sender e String sqlText SELECT FROM Orders Fill the Orders table for editing. da new SqlDataAdapter sqlText S ql_ConnectString Stop updating when an error is encountered for roll back. false Create CommandBuilder and generate updating logic. cb new SqlCommandBuilder da Create table and fill with orders schema and data. dt new DataTable ORDERS_TABLE dt dt Bind the default view

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.