C#挪用Oracle存儲進程的辦法。本站提示廣大學習愛好者:(C#挪用Oracle存儲進程的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#挪用Oracle存儲進程的辦法正文
本文實例講述了C#挪用Oracle存儲進程的辦法。分享給年夜家供年夜家參考。詳細完成辦法以下:
Oracle數據庫代碼以下:
create or replace procedure proce_test(paramin in varchar2,paramout out varchar2,paraminout in out varchar2)
as
varparam varchar2(28);
begin
varparam:=paramin;
paramout:=varparam|| paraminout;
end;
c#挪用代碼以下:
OracleConnection conn = null;
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#法式設計有所贊助。