The execution of the SQL statement described in the previous section, this section describes the execution of the stored procedure.
The execution of the stored procedure is done through the Fromproc method.
The execution of the parameter-free stored procedure is as follows:
DbSession.Default.FromProc("Ten Most Expensive Products").ToDataTable();
"Ten Most Expensive Products" is the stored procedure name.
To execute a stored procedure with parameters:
DbSession.Default.FromProc("Sales by Year")
.AddInParameter("Beginning_Date", DbType.DateTime, "1995-01-01")
.AddInParameter("Ending_Date", DbType.DateTime, "1996-12-01")
.ToDataTable();
The stored procedure in the database
create procedure "Sales by Year"
@Beginning_Date DateTime, @Ending_Date DateTime AS
SELECT Orders.ShippedDate, Orders.OrderID, "Order Subtotals".Subtotal, DATENAME(yy,ShippedDate) AS Year
FROM Orders INNER JOIN "Order Subtotals" ON Orders.OrderID = "Order Subtotals".OrderID
WHERE Orders.ShippedDate Between @Beginning_Date And @Ending_Date
GO
There are two parameters, respectively, Beginning_date and Ending_date.
Stored procedures are similar to the execution of SQL statements, but there are many parameters to the stored procedure, that is, input and output parameters.
Pass
Addinputoutputparameter method to add input and output parameters
Addoutparameter method to add output parameters
Addreturnvalueparameter method Add return parameter
The execution of stored procedures is also very simple.
The next section describes Dbsession's other simple helper methods.