Executing a Stored Procedure

There are a few different ways to execute stored procedures within ADO.NET. The first section following uses methods you've already seen. Then, you'll see the generally accepted standard way of executing the stored procedure.

Using Exec()

In Hour 6, “Retrieving Data from the Data Source,” you saw how to create Connection, Command, and DataReader objects and use them to retrieve data from your database. As you recall, the ExecuteReader() method of the DataReader object returns a forward-only, read-only resultset, which you can then use to bind to a list control, or step through manually.

Almost precisely the same code can be reused to call a stored procedure. Rather than placing a query into the Command object, you ...

Get Sams Teach Yourself ADO.NET in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.