zoukankan      html  css  js  c++  java
  • oracle 通用事务使用

    private void dothing()
            {
    
                OracleConnection con = DBHelperOracle.init();
                 
                OracleTransaction tran = con.BeginTransaction();
    
                try
                {
    
                    DBHelperOracle.ExecuteNonQuery(tran, CommandType.Text, @"
    update  xxxxxx",
                                                                                                                    null);
                    DataTable dt = DBHelperOracle.ExecuteTable(tran, CommandType.Text, @"selectxxxxxx", null);
    
                    DBHelperOracle.ExecuteNonQuery(tran, CommandType.Text, @"
    update t0070_enterprise set C0047_SECRET_CODE='1' where c0070_enterprise_code ='370682006' and  c0003_year=2006",
                                                                                                                  null);
                    dt = DBHelperOracle.ExecuteTable(tran, CommandType.Text, @"select a.C0047_SECRET_CODE from t0070_enterprise a where a.c0070_enterprise_code ='370682006' and  a.c0003_year=2006", null);
    
    
                    
                    tran.Commit();
    
                }
    
                catch
                {
    
                    tran.Rollback();
    
                }
    
                finally
                {
    
                    if (con.State == ConnectionState.Open)
                    {
                        con.Close();
    
                    }
                }
            }
    
             public static OracleConnection init()
            {
                try
                {
                    conn = new OracleConnection(connstr);
                    if (conn.State != ConnectionState.Open)
                    {
                        conn.Open();
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message.ToString());
                }
                return conn;
            }
    
    
             public static int ExecuteNonQuery(OracleTransaction trans, CommandType cmdType, string cmdText, params OracleParameter[] CommandParams)
            {
    
                OracleCommand cmd = new OracleCommand();
                PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, CommandParams);
                /*if (cmdType == CommandType.StoredProcedure)
                {
                cmd.Parameters.Add("@RETURN_VALUE", "").Direction = ParameterDirection.ReturnValue;
                cmd.ExecuteNonQuery();
    
                val = (int)cmd.Parameters["@RETURN_VALUE"].Value;
                }
                else
                if (cmdType==CommandType.Text)
                {
                val = cmd.ExecuteNonQuery();
                }*/
                int val = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
    
                return val;
            }
    
            public static DataTable ExecuteTable(OracleTransaction trans, CommandType cmdType, string cmdText, params OracleParameter[] CommandParams)
            {
                DataTable temptable = new DataTable();
                OracleCommand cmd = new OracleCommand();
    
                PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, CommandParams);
                OracleDataAdapter da = new OracleDataAdapter(cmd);
                OracleCommandBuilder scb = new OracleCommandBuilder(da);
                da.Fill(temptable);
                cmd.Parameters.Clear();
    
                return temptable;
    
            }
    
            private static void PrepareCommand(OracleCommand cmd, OracleConnection conn, OracleTransaction trans, CommandType cmdType, string cmdText, OracleParameter[] cmdParms)
            {
    
                if (conn.State != ConnectionState.Open)
                    conn.Open();
    
                cmd.Connection = conn;
                cmd.CommandText = cmdText;
    
                if (trans != null)
                    cmd.Transaction = trans;
    
                cmd.CommandType = cmdType;
    
                if (cmdParms != null)
                {
                    foreach (OracleParameter parm in cmdParms)
                        cmd.Parameters.Add(parm);
                }
            }
    

      

  • 相关阅读:
    面向对象知识点2
    面向对象知识点1
    面向对象知识点
    常用模块
    模块与包
    迭代器相关知识
    jquery.jqprint-0.3.js打印功能 以及页眉页脚设置显示与否
    js和layerjs配合实现的拖拽表格列
    iframe中跳转页面的区别
    select3搜索下拉树
  • 原文地址:https://www.cnblogs.com/sishahu/p/11981296.html
Copyright © 2011-2022 走看看