tailieunhanh - Beginning VB 2008 Databases From Novice to Professional phần 9

nhấp vào các nút Submit của, mà cuối cùng sẽ đọc các giá trị từ các hộp văn bản. Để đạt được điều này, tiếp tục với các bước sau ây giờ thêm đoạn mã sau trong sự kiện này btnSubmit_Click để đạt được chức năng mong muốn: | Simpo PDF Merge and Split Unregistered Version - http CHAPTER 16 HANDLING EXCEPTIONS 323 Try It Out Handling a Database Exception Part 1 RAISERROR Here you ll see how to raise a database error and handle the exception. 1. Add a button to the Database tab page and change its Text property to Database Exception-1. Add a label to the right of this button and for its Text property type Calls a stored procedure that uses RAISERROR. 2. Add a second button to the tab page and change its Text property to Database Exception-2. Add a label to the right of this button and for its Text property type Calls a stored procedure that encounters an error. 3. Add a third button to the tab page and change its Text property to Database Exception-3. Add a label to the right of this button and for its Text property type Creates multiple SqlError objects. The layout should look like Figure 16-7. Figure 16-7. Database tab page 4. Using SSMSE create a stored procedure in Northwind named sp_DbException_1 as follows create procedure sp_DbException_1 as set nocount on declare @ordercount int Select @ordercount count From Orders if @ordercount 10 raiserror Orders Count is greater than 10 - Notify the Business Manager 16 1 Simpo PDF Merge and Split Unregistered Version - http 324 CHAPTER 16 HANDLING EXCEPTIONS 5. Add the code in Listing 16-4 to the button3_Click method. Listing 16-4. button3_Click Dim conn As SqlConnection New SqlConnection _ Data Source . sqlexpress _ Integrated Security True _ database northwind create command Dim cmd As SqlCommand Specify that a stored procedure is to be executed sp_DbException_1 Try Open connection Execute stored procedure Catch ex As Dim str As String str Source str Number str Message str .

TỪ KHÓA 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.