Database Component Hxj.data (eight) (stored procedure article)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.