Retrieving Data with Stored Procedures

When you work with stored procedures, you often need to provide parameters to them that affect their execution. The stored procedure might simply wrap a query that will return rows of data, or it might update, insert, or delete data in the database. In any of these cases, you usually have to tell the stored procedure which sets of data to operate on, and you do this through parameters.

Let's start with a simple example. In the Northwind database, there is a stored procedure defined named CustOrderHist. You provide it with a customer ID, and it will return a result set containing a summary of products and their quantity ordered by that customer. To call a stored procedure using ADO.NET, you use the SqICommand class, as demonstrated earlier in this appendix. However, you need to tell the command object that you are calling a stored procedure instead of providing a textual query. You also need to provide the command object with any parameters that need to be passed to the stored procedure that it will execute. You do this as shown in Listing D.6.

0 0

Post a comment