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存储过程的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
推荐阅读
- 节省|节省 58% IT 成本,调用函数计算超过 30 亿次,石墨文档的 Serverless 实践
- kubernetes配置后端存储|kubernetes配置后端存储 rook-ceph
- bmaplib|bmaplib vue 调用_vue引入百度地图BMapGL,以及辅助工具BMapGLLib 的引入,BMapGL鼠标绘制功能。...
- 自己写了个Java|自己写了个Java RMI(远程方法调用)的实现案例
- Android存储访问框架的使用小结
- spring|spring retry方法调用失败重试机制示例解析
- 虚拟存储技术与交换覆盖技术的区别
- 关于C#|关于C# 调用Dll 传递字符串指针参数的问题
- C游记|《C游记》 第陆章 - 数据类型悟正法 解析存储定风魔(贰)
- C游记|《C游记》 第陆章 - 数据类型悟正法 解析存储定风魔(壹)