html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

Oracle利用游标返回结果集的的例子(C#)_.NET教程_编程技术

[ ] 已经帮助:人解决问题
oracle|游标
本例在VS2005+Oracle 92010 + WindowsXp Sp2测试通过
1、创建一个游标变量,为返回值使用
create or replace package types as
  type cursorType is ref cursor;
end;
2、创建函数(或者存储过程)
create or replace function testpro return types.cursorType is
lc types.cursorType;
begin
  open lc for select * from test;
  return lc;
end testpro;
3、编写C#程序(注意:要先应用System.Data.OracleClient)
            OracleConnection conn = new OracleConnection("YourConnectString");
            OracleCommand cmd = new OracleCommand("testpro", conn);
            cmd.CommandType = CommandType.StoredProcedure;
 
            OracleParameter op = new OracleParameter("c", OracleType.Cursor);
            op.Direction = ParameterDirection.ReturnValue; 
            cmd.Parameters.Add(op);
 
            DataSet ds = new DataSet();
            OracleDataAdapter da = new OracleDataAdapter(cmd);
 
            da.Fill(ds,"test");
 
            this.dataGridView1.DataSource = ds.Tables["test"];
PS:使用储过程方法类似。

VgfHTML5中文学习网 - HTML5先行者学习网
VgfHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助