You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by "Saed Imran . netzkern" <sa...@netzkern.de> on 2007/10/25 18:17:12 UTC

calling stored procedure using ibatis in .net

Hi,

Iam a newbee to .net and iBatis . I want to call stored procedure over ibatis and get back the record. Can any one help me out how to write a sqlmap for a stored procedure for c# and mssql server 2005 and how to call it from inside the c# client. I am sending what ever I did till now please have a look. Your guidance is very valuable for me.

Regards
imran

Following is the stored procedure

CREATE PROCEDURE custsp
                @cust_id int
AS
SELECT * FROM [dbo].[customer]
WHERE cust_id=@cust_id


Following is the sqlmap  customer.xml

<?xml version="1.0" encoding="UTF-8" ?>

<sqlMap namespace="customer" xmlns="http://ibatis.apache.org/mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


  <alias>
    <typeAlias alias="customerData" type="TELE2.Customer.Replica.Customer.DataService.customerData" />
  </alias>

  <resultMaps>
    <resultMap id="custResult" class="customerData">
      <result property="Id" column="id"/>
      <result property="Name" column="name"/>
      <result property="Fname" column="fname"/>
      <result property="Email" column="email"/>
      <result property="CustId" column="cust_id"/>
    </resultMap>
  </resultMaps>

  <statements>
  <procedure id="custProc" parameterMap="custParam">
    custsp
   </procedure>
  </statements>

  <parameterMaps>
      <parameterMap id="custParam" class="customerData">
        <parameter property="custId" column="cust_id" direction="Input" dbType="Int" type="int"/>
      </parameterMap>
   </parameterMaps>

</sqlMap>


Code to call stored procedure:
customerData cd = new customerData();
int key = 1;
cd = Mapper.Instance().QueryForObject("custProc", key) as customerData;