日期:2011-06-13  浏览次数:20367 次

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