c#使用oracle存储过程获取结果集实例

来源:互联网 发布:c语言共用体赋值 编辑:程序博客网 时间:2024/06/10 01:08

存储过程:

create or replace PACKAGE FIRSTPAGE AS

  /* TODO enter package declarations (types, exceptions, methods etc) here */
   type v_cursor is REF CURSOR;
   procedure getnumber(re_cursor out v_cursor);
END FIRSTPAGE;


create or replace PACKAGE BODY FIRSTPAGE AS

  procedure getnumber(re_cursor out v_cursor) AS
  BEGIN
    /* TODO implementation required */
   open re_cursor for
     select * from testable;
  END getnumber;

END FIRSTPAGE;

C#代码:

public DataSet GetTableByProcedure()
        {
            OracleConnection con = new OracleConnection(_connectionString);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = con;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "firstpage.getnumber";

            OracleParameter sp = new OracleParameter("re_cursor", OracleType.Cursor);
            sp.Direction = ParameterDirection.Output;
            cmd.Parameters.Add(sp);

            OracleDataAdapter da = new OracleDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);

            cmd.Dispose();
            con.Close();
            con.Dispose();

            return ds;

        }

原创粉丝点击