这是最简单的例子,oracle存储过程返回数据集要比sqlserver麻烦的多,用惯sql的人可能会非常不习惯,下面做了个最简单的例子。
首先建个包:
create or replace package temppkg
is
type mytable is ref cursor;
procedure Get_Template(cur_mytable out mytable);
end;
create or replace package body temppkg
is
procedure Get_Template(cur_mytable out mytable)
is
begin
open cur_mytable for select * from tj_template_data;
end Get_Template;
end temppkg;
c#里:
OracleConnection con = new OracleConnection(strConnection);
OracleCommand comm = new OracleCommand("temppkg.Get_Template", con);
comm.Parameters.Add("cur_mytable", OracleType.Cursor);
comm.Parameters[0].Direction = ParameterDirection.Output;
comm.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
OracleDataAdapter ada = new OracleDataAdapter();
ada.SelectCommand = comm;
ada.Fill(ds, "mytable");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = ds.Tables[0].TableName;