In fact, the method of invocation is relatively simple, mainly two types of stored procedures:
1. Update type of stored procedure
2. Query type of stored procedure
Here's a look at the specific invocation method:
1. Update type of stored procedure
Sp_insertaccount:
CREATE PROCEDURE [dbo]. [Sp_insertaccount]
--Add The parameters for the stored procedure here
@Account_ID int,
@Account_FirstName varchar (32),
@Account_LastName varchar (+) AS
BEGIN
Insert into accounts (account_id, Account_firstname, Account_lastname)
VALUES (@Account_ID, @Account_FirstName, @Account_LastName)
END
Map configuration file:
<procedure id= "Insertaccountviastoreprocedure" parametermap= "Insert-params_new" >
Sp_insertaccount
</procedure>
<parametermap id= "insert-params_new" class= "Account" >
<parameter property= "Id"/>
<parameter property= "FirstName"/>
<parameter property= "LastName"/>
</parameterMap>
It is important to note that the number and order of parameters in the Parametermap are consistent with the sp_insertaccount stored procedure.
The calling code in ADO:
public void Insertaccountviastoreprocedure
{
Try
{
sqlmap.insert ("Insertaccountviastoreprocedure", account);
}
catch (DataAccessException ex)
{
throw new dataaccessexception ("Error executing insertaccountviastoreprocedure. cause : " + ex. MESSAGE,&NBSP;EX);
}
}
Here is the method of Sqlmap.insert, in order to look intuitive, in fact, the use of the Sqlmap.queryforobject method is the same effect:)
2. Query type of stored procedure
getaccountbyname:
CREATE PROCEDURE [dbo]. [Getaccountbyname]
@name varchar (32)
As
BEGIN
SELECT * from accounts where account_firstname like '% ' + @name + '% '
END
Map configuration file:
<procedure id= "Getaccountbynameviastoreprocedure" resultmap= "Account-result" parametermap= "Selectpro-params" >
Getaccountbyname
</procedure>
<parametermap id= "Selectpro-params" class= "string" >
<parameter property= "Name"/>
</parameterMap>
Here Parametermap is also the same as the above requirements, as to the name of the property here does not have a practical role, can be arbitrarily named
The calling code in ADO:
Public ArrayList getaccountbynameviastoreprocedure (string strName)
{
Try
{
ArrayList list = (ArrayList) sqlmap.queryforlist ("Getaccountbynameviastoreprocedure", strName);
return list;
}
catch (DataAccessException ex)
{
throw new DataAccessException ("Error executing Sqlaccountviasqlmapdao.getaccountbyid. Cause: "+ ex. Message, ex);
}
}http://www.cnblogs.com/firstyi/archive/2008/01/25/1053208.html
Ibatis.net Learning Note 13: Calling a stored procedure in ibatis.net