C#調(diào)用Oracle存儲過程方法介紹(附源碼)
更新時間:2022年03月04日 09:59:20 作者:.NET開發(fā)菜鳥
這篇文章介紹了C#調(diào)用Oracle存儲過程的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
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存儲過程的文章就介紹到這了。希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C#通過chrome插件將HTML網(wǎng)頁轉(zhuǎn)換為PDF
這篇文章主要介紹了C#通過chrome插件將HTML網(wǎng)頁轉(zhuǎn)換為PDF,將HTML網(wǎng)頁內(nèi)容轉(zhuǎn)換為 PDF 格式能方便文檔的后續(xù)打印、存檔和分享等,文中有相關(guān)的代碼示例供大家參考,需要的朋友可以參考下2025-03-03
C#實現(xiàn)讀取匿名對象屬性值的方法示例總結(jié)
這篇文章主要介紹了C#實現(xiàn)讀取匿名對象屬性值的方法,結(jié)合實例形式總結(jié)分析了C#通過反射、轉(zhuǎn)換等方法讀取匿名對象屬性值的相關(guān)操作技巧,需要的朋友可以參考下2020-03-03
Unity實現(xiàn)鼠標點2D轉(zhuǎn)3D進行旋轉(zhuǎn)
這篇文章主要為大家詳細介紹了Unity實現(xiàn)鼠標點2D轉(zhuǎn)3D進行旋轉(zhuǎn),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-04-04

