日期:2014-05-20  浏览次数:20859 次

在ASP.NET如何调用ORACLE的存储过程,返回字录集
ORACLE端建立了一个存储过程
Create   Table   T_TEST(A   CHAR(1),   B   CHAR(1));
 
Insert   Into   T_TEST   ( '1 ',   '1 ');
Insert   Into   T_TEST   ( '2 ',   '2 ');
Insert   Into   T_TEST   ( '3 ',   '3 ');
commit;
 
Create   Or   Replace   Procedure   P_TEST   (Cursor_Parameter   out   sys_refcursor)     as
begin
    open   Cursor_Parameter   for   select   *   from   T_TEST;
end   P_TEST;
/
 
创建好了以后,调用:
 
declare
res   sys_refcursor;
lop   t_test%rowtype;
begin
    p_test(res);
    loop
        fetch   res   into   lop;
        exit   when   res%notfound;
        dbms_output.put_line(lop.a|| '     '||lop.b|| '     '||lop.c);
    end   loop;
end;

出力结果都没有问题
1     1
2     2
3     3

但如果我想用.NET调用,返回记录集和DATAGRID绑定,如何做??

------解决方案--------------------
很简单的。。
给你个参考
switch(a)
{
case 1:
s= "SEL_STU_INFO.GET_LATE ";break;
case 2:
s= "SEL_STU_INFO.GET_EARLY ";break;
case 3:
s= "SEL_STU_INFO.GET_ABSENCE ";break;
case 4:
s= "SEL_STU_INFO.GET_QINGJIA ";break;
}
OracleConnection myConnection=new OracleConnection(ConfigurationSettings.AppSettings[ "OracleConnString "]);
myConnection.Open();
OracleCommand Ocmd=new OracleCommand(s,myConnection);
Ocmd.CommandType=CommandType.StoredProcedure;
OracleParameter xh=new OracleParameter();
xh.ParameterName= "p_XH ";
xh.OracleType=OracleType.VarChar;
xh.Size=12;
xh.Direction=ParameterDirection.Input;
xh.Value=nu;
Ocmd.Parameters.Add(xh);

OracleParameter tout=new OracleParameter();
switch(a)
{
case 1:
tout.ParameterName= "cur_LATE ";break;
case 2:
tout.ParameterName= "cur_EARLY ";break;
case 3:
tout.ParameterName= "cur_ABSENCE ";break;
case 4:
tout.ParameterName= "cur_QINGJIA ";break;

}
tout.OracleType=OracleType.Cursor;
tout.Direction=ParameterDirection.Output;
Ocmd.Parameters.Add(tout);
Ocmd.ExecuteNonQuery();