通过.NET访问 Oracle数据库[2]

[入库:2005年8月18日] [更新:2007年3月27日]

本文简介:选择自 flyingfish2046 的 blog

go

  在 oracle 中,请按以下步骤操作:

(1)创建一个包,含有一个游标类型:(一个数据库中只需作一次)

create or replace package test
  as
       type test_cursor is ref cursor;
end test;

(2)过程:

create or replace procedure getcategorybooks
(
     p_cursor out test.test_cursor,    -- 这里是上面包中的类型,输出参数
     p_catogoryid integer
)
as
begin
     open p_cursor for
           select * from books
           where categoryid=p_catogoryid;
end getcategorybooks;

(3).net 程序中:

oracleparameters parameters = {
     new oracleparameter("p_cursor", oracletype.cursor, 2000, parameterdirection.output, true, 0, 0, "",
          datarowversion.default, convert.dbnull),
     new oracleparameter("p_catogoryid", oracletype.int32)
};

parameters[1].value = 22;

oracleconnection connection = new oracleconnection( connectionstring );
oraclecommand command = new oraclecommand("getcategorybooks", connection);
command.commandtype = commandtype.storedprocedure;

foreach(oracleparameter parameter in parameters)
     command.parameters.add( parameter );

connection.open();
oracledatareader dr = command.executereader();

while(dr.read())
{
    // 你的具体操作。这个就不需要我教吧?
}
connection.close();

  另外有一点需要指出的是,如果使用 datareader 取得了一个记录集,那么在 datareader 关闭之前,程序无法访问输出参数和返回值的数据。

  好了,先这些,总之 .net 访问 oracle 还是有很多地方和 sql server 不同的,慢慢学习了

本文关键:,通过.NET访问 Oracle数据库,
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top