最近有人问我怎么获取存储过程的output的参数值,由于我最近没有用Ibatis.net,所以就从文档中找到的param的xml,也就没有在意,但后来有人说调不通,今天早上又收到一份留言,所以我早上作了测试!也出现获取不到数据的问题,但最后还是解决了!我的测试环境是sqlserver2005/vs2005/ibatis.net2.0
如下:
procedure:

IBatis.Net如何获取存储过程的Output的参数值create proc sp_output
IBatis.Net如何获取存储过程的Output的参数值(
IBatis.Net如何获取存储过程的Output的参数值    
@testParam    int    output
IBatis.Net如何获取存储过程的Output的参数值)
IBatis.Net如何获取存储过程的Output的参数值
as
IBatis.Net如何获取存储过程的Output的参数值
begin
IBatis.Net如何获取存储过程的Output的参数值    
set @testParam = 10
IBatis.Net如何获取存储过程的Output的参数值
end
IBatis.Net如何获取存储过程的Output的参数值
go
IBatis.Net如何获取存储过程的Output的参数值

xml:
IBatis.Net如何获取存储过程的Output的参数值  <parameterMaps>
IBatis.Net如何获取存储过程的Output的参数值    
<parameterMap id="select-params2" class="Hashtable">
IBatis.Net如何获取存储过程的Output的参数值      
<parameter property="testParam" column="testParam" direction="Output" />
IBatis.Net如何获取存储过程的Output的参数值    
</parameterMap>
IBatis.Net如何获取存储过程的Output的参数值  
</parameterMaps>
IBatis.Net如何获取存储过程的Output的参数值
IBatis.Net如何获取存储过程的Output的参数值  
<statements>
IBatis.Net如何获取存储过程的Output的参数值
IBatis.Net如何获取存储过程的Output的参数值    
<procedure id="GetAccountViaSP2" parameterMap="select-params2">
IBatis.Net如何获取存储过程的Output的参数值      sp_output
IBatis.Net如何获取存储过程的Output的参数值    
</procedure>
IBatis.Net如何获取存储过程的Output的参数值  
</statements>

code:
IBatis.Net如何获取存储过程的Output的参数值int testid = 0;
IBatis.Net如何获取存储过程的Output的参数值            Hashtable map 
= new Hashtable();
IBatis.Net如何获取存储过程的Output的参数值            map.Add(
"testParam", testid);
IBatis.Net如何获取存储过程的Output的参数值
IBatis.Net如何获取存储过程的Output的参数值            mapper.Insert(
"GetAccountViaSP2", map);
IBatis.Net如何获取存储过程的Output的参数值
IBatis.Net如何获取存储过程的Output的参数值            Console.WriteLine(map[
"testParam"].ToString());

注意,在parammap定义的时候需要设置class=Hashtable,用class=int,就获取不到!
希望对读者有帮助!有任何问题可以发邮件给我mapley@gmail.com

相关文章: