Oracle利用游标返回结果集的的例子(C#)

80酷酷网    80kuku.com

  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:使用储过程方法类似。

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: