原創|使用教程|編輯:郝浩|2013-04-18 14:04:12.000|閱讀 1996 次
概述:今天來看看如何在dotConnect for Oracle中創建和使用Oracle存儲過程,在OracleCommand類的幫助下用于Oracle的連接的函數。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
今天來看看如何在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,使用存儲功能而不是進程,相同的代碼也將會填充數據表格。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件