本文实例讲述了C#调用Oracle存储过程的方法。分享给大家供大家参考。具体实现方法如下:
Oracle数据库代码如下:
代码如下:
as
varparam varchar2(28);
begin
varparam:=paramin;
paramout:=varparam|| paraminout;
end;
c#调用代码如下:
代码如下:
OracleCommand cmd = null;
string strConn = “data source=clientag;user id=ay_plan;password=ayplan”; //连接数据库
conn = new OracleConnection(strConn);
try
{
conn.Open();
cmd = new OracleCommand();
cmd.Connection = conn;
}
catch (Exception e)
{
throw e;
}
OracleParameter[] parameters ={
new OracleParameter(“paramin”,OracleType.VarChar,20),
new OracleParameter(“paramout”,OracleType.VarChar,20),
new OracleParameter(“paraminout”,OracleType.VarChar,20)
};
parameters[0].Value = “bjd”;
parameters[2].Value = “cs”;
parameters[0].Direction = ParameterDirection.Input;
parameters[1].Direction = ParameterDirection.Output;
parameters[2].Direction = ParameterDirection.InputOutput;
try
{
cmd.CommandText = “proce_test”;//声明存储过程名
cmd.CommandType = CommandType.StoredProcedure;
foreach (OracleParameter parameter in parameters)
{
cmd.Parameters.Add(parameter);
}
cmd.ExecuteNonQuery();//执行存储过程
Console.WriteLine(parameters[1].Value.ToString());
Console.Read();
}
catch (Exception e)
{
throw e;
}
C#调用Oracle存储过程的方法
本文地址: http://www.paobuke.com/develop/c-develop/pbk23179.html