IBatis.Net如何获取存储过程的Output的参数值
最近有人问我怎么获取存储过程的output的参数值,由于我最近没有用Ibatis.net,所以就从文档中找到的param的xml,也就没有在意,但后来有人说调不通,今天早上又收到一份留言,所以我早上作了测试!也出现获取不到数据的问题,但最后还是解决了!我的测试环境是sqlserver2005/vs2005/ibatis.net2.0
如下:
procedure:
create proc sp_output
(
@testParam int output
)
as
begin
set @testParam = 10
end
go
(
@testParam int output
)
as
begin
set @testParam = 10
end
go
xml:
<parameterMaps>
<parameterMap id="select-params2" class="Hashtable">
<parameter property="testParam" column="testParam" direction="Output" />
</parameterMap>
</parameterMaps>
<statements>
<procedure id="GetAccountViaSP2" parameterMap="select-params2">
sp_output
</procedure>
</statements>
<parameterMap id="select-params2" class="Hashtable">
<parameter property="testParam" column="testParam" direction="Output" />
</parameterMap>
</parameterMaps>
<statements>
<procedure id="GetAccountViaSP2" parameterMap="select-params2">
sp_output
</procedure>
</statements>
code:
int testid = 0;
Hashtable map = new Hashtable();
map.Add("testParam", testid);
mapper.Insert("GetAccountViaSP2", map);
Console.WriteLine(map["testParam"].ToString());
Hashtable map = new Hashtable();
map.Add("testParam", testid);
mapper.Insert("GetAccountViaSP2", map);
Console.WriteLine(map["testParam"].ToString());
注意,在parammap定义的时候需要设置class=Hashtable,用class=int,就获取不到!
希望对读者有帮助!有任何问题可以发邮件给我mapley@gmail.com