SQL 封装 oracle

 public DataTable ExecuteSqlDt(string strSql)  //执行SQL 
        {

            DbConnection connection = _db.CreateConnection();
            DataTable dt = null;
            try
            {
                connection.Open();
                DbCommand cmd = _db.GetSqlStringCommand(strSql);
                cmd.Connection = connection;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = strSql;

                IDataReader dataReader = _db.ExecuteReader(cmd);
                dt = new DataTable();

                dt.Load(dataReader);
            }
            catch (Exception ex)
            {
                _log.Warn("执行sql失败", ex);
                throw;
            }
            finally
            {
                if (connection != null) connection.Close();
            }
            return dt;
        }
 public bool ExecuteSql(string strSql)//执行SQL  有更新或者插入删除时  需做commit   Oracle
        {
            bool result = false;
            int effRows = 0;

            DbConnection connection = _db.CreateConnection();
            DbTransaction transaction = null;

            try
            {
                connection.Open();
                transaction = connection.BeginTransaction();

                DbCommand cmd = _db.GetSqlStringCommand(strSql);

                cmd.Connection = connection;
                cmd.CommandType = CommandType.Text;
                cmd.Transaction = transaction;
                cmd.CommandText = strSql;
                effRows = cmd.ExecuteNonQuery();
                transaction.Commit();

                if (effRows > 0 || effRows == -1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                if (transaction != null)
                    transaction.Rollback();
                _log.Warn("执行sql失败", ex);
                throw;
            }
            finally
            {
                if (connection != null) connection.Close();
            }
            return result;
        }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值