C#调用Oracle存储过程方法介绍(附源码)

【C#调用Oracle存储过程方法介绍(附源码)】C#调用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"; // 存储过程参数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)}; // 设置存储过程参数数组的值和参数的类型parameters[0].Valuehttps://www.it610.com/article/= "https://www.it610.com/article/2017-06-01"; parameters[0].Direction = ParameterDirection.Input; parameters[1].Valuehttps://www.it610.com/article/= "https://www.it610.com/article/2017-07-31"; parameters[1].Direction = ParameterDirection.Input; parameters[2].Value = https://www.it610.com/article/1; parameters[2].Direction = ParameterDirection.Input; parameters[3].Value =""; parameters[3].Direction = ParameterDirection.Input; parameters[4].Valuehttps://www.it610.com/article/= ""; parameters[4].Direction = ParameterDirection.Input; parameters[5].Valuehttps://www.it610.com/article/= ""; parameters[5].Direction = ParameterDirection.Input; parameters[6].Valuehttps://www.it610.com/article/= "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){// 添加参数cmd.Parameters.AddRange(parameters); }// 取数据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; }}}

示例代码下载地址:点此下载
到此这篇关于C#调用Oracle存储过程的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

    推荐阅读