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