Pulling Information Using DataReader With ADO.NET - How to retrieve a single row returned by a stored procedure using DataReader in ADO.NET from ASP.NET: stored procedure
(Page 4 of 5 )
In the previous section, we worked on returning single values and handling them using “DataReader.” We shall extend this concept to an entire row.
Before going into the ADO.NET code, we need to create a simple stored procedure in SQL Server which returns some value. Using “Query Analyzer,” execute the following script in the “Northwind” database.
CREATE PROCEDURE dbo.sp_emp_getEmployeeDetails
(
@empno int
)
AS
SELECT * FROM emp
WHERE empno = @empno
RETURN
The above stored procedure simply uses a SELECT statement to retrieve an entire row related to an employee from the table “EMP” based on the “EMPNO” we send through the parameter “@EMPNO.” The stored procedure is named “sp_Emp_getEmployeeDetails.” Now, we need to go for ADO.NET to access the same in ASP.NET.
The steps would be very similar to the ones I specified in the first section. I shall directly work with the code now. Add a new web form (call it “SPReturningRow”) with a single button captioned “Retrieve Employee Details” and a few labels to display employee information.
The next section will give you the code.
Next: How to retrieve a single row returned by a stored procedure using DataReader in ADO.NET from ASP.NET: the code >>
More MS SQL Server Articles
More By Jagadish Chaterjee