原創(chuàng)|使用教程|編輯:郝浩|2013-04-18 14:04:12.000|閱讀 1996 次
概述:今天來(lái)看看如何在dotConnect for Oracle中創(chuàng)建和使用Oracle存儲(chǔ)過程,在OracleCommand類的幫助下用于Oracle的連接的函數(shù)。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
今天來(lái)看看如何在dotConnect for Oracle中創(chuàng)建和使用Oracle存儲(chǔ)過程,在OracleCommand類的幫助下用于Oracle的連接的函數(shù)。
通過oraclecommand執(zhí)行存儲(chǔ)過程一般有兩種方式。第一種方法就是包括一個(gè)調(diào)用到一個(gè)PL/SQL塊中,將這個(gè)塊放到OracleCommand.CommandText屬性中,就可以執(zhí)行了。在這種情況下,由存儲(chǔ)過程返回的數(shù)據(jù)可能在同一個(gè)塊中一次處理。如果進(jìn)程需要一些參數(shù),參數(shù)可以被添加到OracleCommand.Parameters集。
第二種方法是將 OracleCommand.CommandType 設(shè)置為 System.Data.CommandType.StoredProcedure。在這種情況下,CommandText 應(yīng)該設(shè)置為過程的名稱。下面的示例演示如何使用get_all_depts_proc來(lái)填充一個(gè)數(shù)據(jù)表:
[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()
設(shè)置CommandText為get_all_depts_func,使用存儲(chǔ)功能而不是進(jìn)程,相同的代碼也將會(huì)填充數(shù)據(jù)表格。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件