Petapoco Accessing SQL SERVER stored procedures

Source: Internet
Author: User

Blog Park has an article "Small and convenient ORM class Library--petapoco" describes the Petapoco call stored procedures:

Call the stored procedure db. Execute ("Exec Procsomehandler @0, @1", 3,"2011-10-01");Calling a stored procedure with an output parameter, the write SQL statement, the "output" after the @0 parameter is the key var param =New SqlParameter () {Direction = ParameterDirection.Output, SqlDbType = SqlDbType.Int};d b. Execute ("Exec procsomehandler @0 OUTPUT", param);

The following describes a stored procedure call that introduces both input parameters and output parameters:
Suppose you have a stored procedure defined as follows:
CREATE PROCEDURE [dbo]. [Sp_pub_serialno_new]
@SerialNoType varchar (30)--the type of business that needs to be numbered
@Year int,--@Year, @Month = 0, using the system's date
@Month int,
@SerialNo varchar () output

The Petapoco call is as follows:

string Jobtype, int iyear,int imonth Set initial value
var param = new SqlParameter ("Serialno", sqldbtype.varchar,30);
Param. Direction = System.Data.ParameterDirection.Output;
DataContext _db = Datacontexthelp.getdatacontextdefault ();
Call a stored procedure to get a business number
var spresult = _db. Execute ("EXEC sp_pub_serialno_new @SerialNoType, @Year, @Month,@SerialNo OUTPUT "
, new {serialnotype=jobtype,year= iyear,month= imonth,serialno= param });
return param. Value.tostring (); Return output parameters

Note the red part:
1. Declaring an output parameter
2.SQL Statement section Add output
3. parameter list inside pass param
4.spResult can read the return value of a stored procedure

Petapoco Accessing SQL SERVER stored procedures

Related Article

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.