C#調(diào)用Oracle存儲過程方法介紹(附源碼)
更新時間:2022年03月04日 09:59:20 作者:.NET開發(fā)菜鳥
這篇文章介紹了C#調(diào)用Oracle存儲過程的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
C#調(diào)用Oracle存儲過程的代碼如下所示:
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)
{
// 存儲過程名稱
string strProcName = "usp_yngr_getInfectionCard";
// 存儲過程參數(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),
// 返回值的類型是游標類型
new OracleParameter("cur_out",OracleType.Cursor)
};
// 設(shè)置存儲過程參數(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("錯誤:" + ex.Message + "/r/n跟蹤:" + ex.StackTrace);
}
finally
{
conn.Close();
}
}
return dt;
}
}
}示例代碼下載地址:點此下載
到此這篇關(guān)于C#調(diào)用Oracle存儲過程的文章就介紹到這了。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
關(guān)于javascript冒泡與默認事件的使用詳解
本篇文章是對javascript中冒泡與默認事件的使用進行了詳細的分析介紹,需要的朋友參考下2013-05-05
C#/VB.NET?將Word與Excel文檔轉(zhuǎn)化為Text
這篇文章主要介紹了C#/VB.NET?將Word與Excel文檔轉(zhuǎn)化為Text,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的朋友可以參考一下2022-08-08
描述C#多線程中l(wèi)ock關(guān)鍵字的使用分析
本篇文章是對C#多線程中l(wèi)ock關(guān)鍵字的使用進行了詳細的分析介紹,需要的朋友參考下2013-06-06
C#操作DataTable方法實現(xiàn)過濾、取前N條數(shù)據(jù)及獲取指定列數(shù)據(jù)列表的方法
這篇文章主要介紹了C#操作DataTable方法實現(xiàn)過濾、取前N條數(shù)據(jù)及獲取指定列數(shù)據(jù)列表的方法,實例分析了C#操作DataTable的各種常用技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04
C# 開發(fā)(創(chuàng)藍253)手機短信驗證碼接口的實例
下面小編就為大家分享一篇C# 開發(fā)(創(chuàng)藍253)手機短信驗證碼接口的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01

