萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> 編程語言綜合 >> ado.net執行oracle 存儲過程

ado.net執行oracle 存儲過程

   ado.net執行oracle 存儲過程如下:

  OracleConnection con=new OracleConnection(strcon);

  OracleCommand cmd=new OracleCommand();

  OracleTransaction mytrans ;

  try

  {

  con.Open ();

  mytrans =con.BeginTransaction();

  cmd.Connection =con;

  cmd.CommandText ="rfgetid";

  cmd.CommandType =CommandType .StoredProcedure;

  cmd.Transaction =mytrans ;

  OracleParameter parameter_in=new OracleParameter("as_bm",OracleType.Char);

  OracleParameter parameter_out=new OracleParameter ("as_sxh",OracleType .Number );

  parameter_in.Direction =ParameterDirection .Input;

  parameter_out.Direction=ParameterDirection .Output ;

  parameter_in .Value =tblname.ToUpper();

  cmd.Parameters .Add(parameter_in );

  cmd.Parameters.Add(parameter_out);

  cmd.ExecuteNonQuery();

  mytrans .Commit();

  return int.Parse(parameter_out .Value.ToString()) ;

  }

  catch(Exception er)

  {

  throw new Exception(er.Message);

  mytrans .Rollback();

  }

  finally

  {

  cmd.Dispose ();

  con.Close ();

  }

copyright © 萬盛學電腦網 all rights reserved