(转)oracle存储过程返回多条记录

 create table userTabel(
  userid
number(10),
  username
varchar2(100),
 
constraint PK_USERID PRIMARY KEY(userid)
);
commit;

insert into userTabel values(1,'Albert');
insert into userTabel values(2,'reboot') ;
insert into userTabel values(3,'Jeff');


--创建包以游标的形式返回userTabel的结果集
create or replace package pkg_AA is

 
-- Author  : ADMINISTRATOR
  -- Created : 2008-07-17 8:35:52
  -- Purpose :
 
 
-- Public type declarations
  type mycur is ref cursor

 
procedure fun_GetRecords(cur_return out mycur);

end pkg_AA;

create or replace package body pkg_AA is

 
-- Function and procedure implementations
  procedure fun_GetRecords(cur_return out mycur)
 
is   
 
begin
  
open cur_return for select * from Usertabel;
   
 
end fun_GetRecords;

end pkg_AA;

 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OracleClient;

public partial class OracleCursor_Default : System.Web.UI.Page
{
   
protected void Page_Load(object sender, EventArgs e)
    {
       
if (!IsPostBack)
        {
           
this.BindGridView();
        }
    }

   
private void BindGridView()
    {
        OracleConnection conn
= new OracleConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        OracleCommand comm
= new OracleCommand("pkg_AA.fun_GetRecords", conn);
        comm.Parameters.Add(
"cur_return", OracleType.Cursor).Direction = ParameterDirection.Output;

        comm.CommandType
= CommandType.StoredProcedure;

        DataSet ds
= new DataSet();
       
using (OracleDataAdapter da = new OracleDataAdapter(comm))
        {

            da.Fill(ds);
        }
       
this.GridView1.DataSource = ds.Tables[0].DefaultView;
       
this.GridView1.DataBind();

    }
}
 

posted @ 2009-12-30 17:28  PROS  阅读(3064)  评论(1)    收藏  举报