Database Library - Tutorial 3:
This tutorial demonstrates how the DB Library can be used to execute a stored procedure on the database and return a DataSet that is filled with the results of the command.
The following code demonstrates how to run a Stored Procedure with a parameter.
|
using (DatabaseObjectSQL dbObj = new DatabaseObjectSQL()) {
} |
The following is the T-SQL code for the stored procedure.
|
SET ANSI_NULLS ONGO SET QUOTED_IDENTIFIER ONGO -- ============================================= -- Author: Ish Singh -- Description: This procedure returns all Orders that match the passed in CustomerID -- ============================================= CREATE PROCEDURE sp_GetOrdersByCustomerID -- Add the parameters for the stored procedure here@CustomerID int = 0AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON;SELECT Orders.*, Customers.FirstName, Customers.LastName FROM Orders INNER JOIN Customers ON Customers.CustomerID = Orders.CustomerID WHERE Customers.CustomerID = @CustomerID END GO |
