TAILIEUCHUNG - Microsoft ADO .NET 4 Step by Step - p 23

Thay vì tạo ra các trường hợp SqlTransaction trực tiếp, bạn tạo kết nối giao dịch cụ thể bằng cách sử dụng phương pháp BeginTransaction đối tượng SqlConnection của. Giao dịch chỉ làm việc trên các kết nối cơ sở dữ liệu mở, cho nên bạn phải gọi phương thức Open của đối tượng kết nối đầu tiên. | 196 Microsoft 4 Step by Step Instead of creating instances of SqlTransaction directly you generate connection-specific transactions using the SqlConnection object s BeginTransaction method. Transactions work only on open database connections so you must call the connection object s Open method first. C using SqlConnection linkToDB new SqlConnection connectionString SqlTransaction envelope Visual Basic Using linkToDB As SqlConnection New SqlConnection connectionString Dim envelope As SqlTransaction After obtaining a transaction object add it to any SqlCommand objects that should be part of the transaction. C ----- Include the transaction in the SqlCommand constructor. SqlCommand updateCommand new SqlCommand sqlText linkToDB envelope ----- Or add it to an existing SqlCommand object. SqlCommand updateCommand new SqlCommand sqlText linkToDB envelope Visual Basic ------ Include the transaction in the SqlCommand constructor. Dim updateCommand As New SqlCommand sqlText linkToDB envelope ------ Or add it to an existing SqlCommand object. Dim updateCommand As New SqlCommand sqlText linkToDB envelope After you ve issued all the transaction-specific commands you can commit or roll back the entire transaction by calling the SqlTransaction object s Commit or Rollback method. Chapter 12 Guaranteeing Data Integrity 197 C ---- Commit the transaction. ---- Rollback the transaction. Visual Basic ----- Commit the transaction. ----- Rollback the transaction. You should always call Commit or Rollback explicitly. If you dispose of the object or allow it to go out of scope without calling one of these two methods the transaction will be rolled back but at a time determined by the .NET garbage collection system. Both Commit and Rollback and the initial BeginTransaction call as well .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.