1. 程式人生 > >C#呼叫Oracle帶輸出資料集的儲存過程

C#呼叫Oracle帶輸出資料集的儲存過程

1、建立一個帶輸出資料集的Oracle儲存過程

create or replace procedure PRO_test(in_top in number,cur_out out sys_refcursor) is
--查詢指定記錄條數的資料,並返回總共記錄數,返回多個數據集
begin
open cur_out for
SELECT * FROM dept_dict where rownum < in_top;
end PRO_test;

2、C#呼叫

Pu_Sys.GetConnObject con = new Pu_Sys.GetConnObject();
OracleConnection conn = new OracleConnection(con.Get_ConnStr());
OracleCommand Dcomm = new OracleCommand("PRO_TEST", conn);
Dcomm.CommandType = CommandType.StoredProcedure;

OracleParameter DpPass = new OracleParameter();
DpPass.Value = 5;
DpPass.Direction = System.Data.ParameterDirection.Input;
DpPass.ParameterName = "in_top";
Dcomm.Parameters.Add(DpPass);


OracleParameter DpOut = new OracleParameter("cur_out", OracleType.Cursor);
DpOut.Direction = System.Data.ParameterDirection.Output;
Dcomm.Parameters.Add(DpOut);
OracleDataAdapter Da = new OracleDataAdapter(Dcomm);
DataSet Ds = new DataSet();
try
{
Da.Fill(Ds);
}
catch (Exception)
{

}

conn.Close();
conn.Dispose();