C#调用oracle存储过程的代码如下所示: using System; using System.Collections.Generic; using System.Collect
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].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)
{
// 添加参数
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;
}
}
}
示例代码下载地址:点此下载
--结束END--
本文标题: C#调用Oracle存储过程方法介绍(附源码)
本文链接: https://lsjlt.com/news/141271.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0