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 .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU LIÊN QUAN
5    176    1
5    255    1
5    106    0
5    121    1
6    103    1
6    107    1
6    121    1
6    103    0
6    140    0
6    98    0
TÀI LIỆU MỚI ĐĂNG
Đã 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.