C#調(diào)用Oracle存儲(chǔ)過程方法介紹(附源碼)
C#調(diào)用Oracle存儲(chǔ)過程的代碼如下所示:
using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Configuration; using System.Data; using System.Data.OracleClient; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace ExecuteProcByOracle { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Btn_LoadData_Click(object sender, EventArgs e) { // 存儲(chǔ)過程名稱 string strProcName = "usp_yngr_getInfectionCard"; // 存儲(chǔ)過程參數(shù) OracleParameter[] parameters = { new OracleParameter("V_BeginTime",OracleType.VarChar), new OracleParameter("V_EndTime",OracleType.VarChar), new OracleParameter("V_DateType",OracleType.Number), new OracleParameter("V_PtName",OracleType.VarChar), new OracleParameter("V_PtChartNo",OracleType.VarChar), new OracleParameter("V_DeptCode",OracleType.VarChar), new OracleParameter("V_CheckedStatus",OracleType.VarChar), // 返回值的類型是游標(biāo)類型 new OracleParameter("cur_out",OracleType.Cursor) }; // 設(shè)置存儲(chǔ)過程參數(shù)數(shù)組的值和參數(shù)的類型 parameters[0].Value = "2017-06-01"; parameters[0].Direction = ParameterDirection.Input; parameters[1].Value = "2017-07-31"; parameters[1].Direction = ParameterDirection.Input; parameters[2].Value = 1; parameters[2].Direction = ParameterDirection.Input; parameters[3].Value = ""; parameters[3].Direction = ParameterDirection.Input; parameters[4].Value = ""; parameters[4].Direction = ParameterDirection.Input; parameters[5].Value = ""; parameters[5].Direction = ParameterDirection.Input; parameters[6].Value = "1"; parameters[6].Direction = ParameterDirection.Input; parameters[7].Direction = ParameterDirection.Output; this.dgv_Demo.DataSource = LoadData(strProcName, parameters); } private DataTable LoadData(string strProcName, params OracleParameter[] parameters) { DataTable dt = new DataTable(); string strConn = ConfigurationManager.ConnectionStrings["HealthHospInfection"].ConnectionString; using (OracleConnection conn = new OracleConnection(strConn)) { try { OracleCommand cmd = new OracleCommand(); cmd.CommandText = strProcName; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; conn.Open(); if (parameters != null) { // 添加參數(shù) cmd.Parameters.AddRange(parameters); } // 取數(shù)據(jù) using (OracleDataAdapter adapter = new OracleDataAdapter(cmd)) { adapter.Fill(dt); } } catch (Exception ex) { MessageBox.Show("錯(cuò)誤:" + ex.Message + "/r/n跟蹤:" + ex.StackTrace); } finally { conn.Close(); } } return dt; } } }
示例代碼下載地址:點(diǎn)此下載
到此這篇關(guān)于C#調(diào)用Oracle存儲(chǔ)過程的文章就介紹到這了。希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
關(guān)于javascript冒泡與默認(rèn)事件的使用詳解
本篇文章是對(duì)javascript中冒泡與默認(rèn)事件的使用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05C#/VB.NET?將Word與Excel文檔轉(zhuǎn)化為Text
這篇文章主要介紹了C#/VB.NET?將Word與Excel文檔轉(zhuǎn)化為Text,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下2022-08-08描述C#多線程中l(wèi)ock關(guān)鍵字的使用分析
本篇文章是對(duì)C#多線程中l(wèi)ock關(guān)鍵字的使用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06C#操作DataTable方法實(shí)現(xiàn)過濾、取前N條數(shù)據(jù)及獲取指定列數(shù)據(jù)列表的方法
這篇文章主要介紹了C#操作DataTable方法實(shí)現(xiàn)過濾、取前N條數(shù)據(jù)及獲取指定列數(shù)據(jù)列表的方法,實(shí)例分析了C#操作DataTable的各種常用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04C# 開發(fā)(創(chuàng)藍(lán)253)手機(jī)短信驗(yàn)證碼接口的實(shí)例
下面小編就為大家分享一篇C# 開發(fā)(創(chuàng)藍(lán)253)手機(jī)短信驗(yàn)證碼接口的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-01-01