TAILIEUCHUNG - Executing SQL Server Stored Procedures phần 1

Executing SQL Server Stored Procedures In Chapter 4, you saw how to create and execute SQL Server stored procedures using TSQL. You execute a stored procedure using the T-SQL EXECUTE statement. | Executing SQL Server Stored Procedures In Chapter 4 you saw how to create and execute SQL Server stored procedures using T-SQL. You execute a stored procedure using the T-SQL EXECUTE statement. In this section you ll see how to execute SQL Server procedures using . In Table shown earlier in this chapter I mentioned the CommandType of StoredProcedure. Although you can use this CommandType to indicate that a command is to execute a stored procedure you re actually better off using the T-SQL EXECUTE command to execute a stored procedure. This is because you can read values that are returned from a stored procedure through a RETURN statement which you can t do when setting the CommandType to StoredProcedure. Also it s a lot easier to understand your code when you use the EXECUTE command. There are a couple of ways you can execute a stored procedure depending on whether your procedure returns a result set a result set is one or more rows retrieved from a table by a SELECT statement . You ll learn these two ways to execute a stored procedure next. Executing a Stored Procedure That Does Not Return a Result Set If your procedure does not return a result set then you use the following steps to execute it 1. Create a Command object and set its CommandText property to an EXECUTE statement containing your procedure call. 2. Add any required parameters for the procedure call to your Command object remembering to set the Direction property for any output parameters to . These output parameters can be defined using the T-SQL OUTPUT keyword in your procedure call or returned using a RETURN statement in your actual procedure. 3. Execute your Command object using the ExecuteNonQuery method. You use this method because the procedure doesn t return a result set. 4. Read the values of any output parameters. You ll see how to use these four steps to call the following two SQL Server stored procedures The first procedure AddProduct will return an .

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.