Working with NULL, OUTPUT and RETURN in ADO.NET - How to work with an OUTPUT parameter of a stored procedure using ADO.NET from ASP.NET: stored procedure
(Page 2 of 4 )
What is an OUTPUT parameter really? We generally use a parameter to send a value into the stored procedure. The OUTPUT parameter of a stored procedure helps us send a value back to the calling environment (in this case, it would be ADO.NET) from within the stored procedure.
The matter can be simplified as follows:
INPUT parameter – value gets passed from the calling environment (ADO.NET) to the stored procedure.
OUTPUT parameter – value gets passed from the stored procedure to the calling environment (ADO.NET).
Before going to the ADO.NET code, we need to create a simple stored procedure in SQL Server with a simple OUTPUT parameter. Using “Query Analyzer,” execute the following script in the “Northwind” database.
CREATE PROCEDURE dbo.sp_emp_getEname
(
@empno int,
@name varchar(20) OUTPUT
)
AS
SELECT @name = ename FROM emp
WHERE empno=@empno
RETURN
The above stored procedure simply retrieves a row from the “emp” table based on the “empno” we provide. The “ename” is retrieved and placed in our OUTPUT parameter “@name” (which can be used in our web form). The stored procedure is named “sp_Emp_getEname.” Now we need to use ADO.NET to access the same in ASP.NET (proceed to the next section).
Next: How to work with an OUTPUT parameter of a stored procedure using ADO.NET from ASP.NET: the code >>
More MS SQL Server Articles
More By Jagadish Chaterjee