码迷,mamicode.com
首页 > 数据库 > 详细

Ado.net 调用oracle存储过程

时间:2015-07-08 12:48:11      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

写这篇的目的是 因为 EF直接执行存储过程 Varchar类型返回参数 直接抛异常 方式1 可以正常执行 方式2不适用varchar 返回参数可以适用

方式1:Ado.net

    public HealthInsurance_PatientInfo GetYBJKData_ByHisId(string strHisid)
        {

            HealthInsurance_PatientInfo entity = new HealthInsurance_PatientInfo();

            #region 初始化存储过程参数
            OracleConnection conn = new OracleConnection(EFContextFactory.GetCurrentDbContext().Database.Connection.ConnectionString);

            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "proc_healthinsurance_seljsxx";

            cmd.Parameters.Add("i_Var_HisId", OracleDbType.Varchar2, 30);
            cmd.Parameters["i_Var_HisId"].Direction = ParameterDirection.Input;
            cmd.Parameters["i_Var_HisId"].Value = strHisid;

            cmd.Parameters.Add("o_Int_StayDays", OracleDbType.Int32);
            cmd.Parameters["o_Int_StayDays"].Direction = ParameterDirection.Output;

            cmd.Parameters.Add("o_Num_CostAmount", OracleDbType.Double);
            cmd.Parameters["o_Num_CostAmount"].Direction = ParameterDirection.Output;

            cmd.Parameters.Add("o_Var_PayOffDate", OracleDbType.Varchar2, 30);
            cmd.Parameters["o_Var_PayOffDate"].Direction = ParameterDirection.Output;


            cmd.Parameters.Add("o_Var_BXLB_Code", OracleDbType.Int32);
            cmd.Parameters["o_Var_BXLB_Code"].Direction = ParameterDirection.Output;

            cmd.Parameters.Add("o_Int_CostDetail_Count", OracleDbType.Int32);
            cmd.Parameters["o_Int_CostDetail_Count"].Direction = ParameterDirection.Output;

            cmd.Parameters.Add("o_Var_Result", OracleDbType.Varchar2, 200);
            cmd.Parameters["o_Var_Result"].Direction = ParameterDirection.Output;
            #endregion;

            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                entity.Result = cmd.Parameters[6].Value.ToString();
                // -1 执行成功  其他 爆出异常
                if (!entity.Result.Equals("-1"))
                {

                    return entity;
                }
                entity.strHisId = cmd.Parameters[0].Value.ToString();
                entity.StayDays = cmd.Parameters[1].Value.ToString();
                entity.CostAmount = cmd.Parameters[2].Value.ToString();
                entity.PayOffDate = cmd.Parameters[3].Value.ToString();
                entity.BXLB_Code = cmd.Parameters[5].Value.ToString();
                entity.CostDetail_Count = cmd.Parameters[4].Value.ToString();
            }
            catch (Exception ex)
            {
                entity.Result = ex.Message;
                return entity;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                    conn.Dispose();
                }
                cmd.Dispose();
            }


            return entity;

        }


方式2 EF调用

    EFContextFactory.GetCurrentDbContext().Database.ExecuteSqlCommand("prco_xxx(a=>:a)",new object{a})

Ado.net 调用oracle存储过程

标签:

原文地址:http://www.cnblogs.com/easyJob/p/4629767.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!