oracle 存储怎么使用,dotConnect for Oracle使用教程:如何通过oraclecommand类使用存储过程...

今天来看看如何在dotConnect for Oracle中创建和使用Oracle存储过程,在OracleCommand类的帮助下用于Oracle的连接的函数。

通过oraclecommand执行存储过程一般有两种方式。第一种方法就是包括一个调用到一个PL/SQL块中,将这个块放到OracleCommand.CommandText属性中,就可以执行了。在这种情况下,由存储过程返回的数据可能在同一个块中一次处理。如果进程需要一些参数,参数可以被添加到OracleCommand.Parameters集。

第二种方法是将 OracleCommand.CommandType 设置为 System.Data.CommandType.StoredProcedure。在这种情况下,CommandText 应该设置为过程的名称。下面的示例演示如何使用get_all_depts_proc来填充一个数据表:

[C#]

// Open the connection

OracleConnection connection

= new OracleConnection("Server=Ora; User Id=Scott; Password = tiger;");

connection.Open();

// Create a command

OracleCommand command = new OracleCommand();

command.Connection = connection;

// Set the CommandType property to execute

// stored procedures or functions by this command

command.CommandType = System.Data.CommandType.StoredProcedure;

// Set the name of procedure or function to be executed

command.CommandText = "get_all_depts_proc";

// The ParameterCheck property should be true to automatically

// check the parameters needed for the procedure execution.

command.ParameterCheck = true;

// At this moment, the command is ready for execution.

// As we have an output cursor parameter, we may use the command to fill a data table.

OracleDataTable dt = new OracleDataTable(command, connection);

dt.Fill();

[Visual Basic]

Dim connection _

As New OracleConnection("Server=Ora; User Id=Scott; Password = tiger;")

connection.Open()

' Create a command.

Dim command = New OracleCommand()

command.Connection = connection

' Set the CommandType property to execute stored procedures or functions by this command.

command.CommandType = System.Data.CommandType.StoredProcedure

' Set the name of procedure or function to be executed.

command.CommandText = "get_all_depts_proc"

' The ParameterCheck property should be true to automatically

' check the parameters needed for the procedure execution.

command.ParameterCheck = True

' At this moment, the command is ready for execution.

' As we have an output cursor parameter, we may use the command to fill a data table.

Dim dt = New OracleDataTable(command, connection)

dt.Fill()

设置CommandText为get_all_depts_func,使用存储功能而不是进程,相同的代码也将会填充数据表格。

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,尊重他人劳动成果

文章转载自:慧都控件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值