资源简介

C#封装的操作Oracle数据库的帮助类,DbHelperOracle.cs

资源截图

代码片段和文件信息

using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace libDbHelper
{
    public class DbHelperOracle
    {
        private OracleConnection m_Conn = null;
        private OracleCommand m_Cmd = null;
        bool bAutoCloseConn = true;

        /// 
        /// Oracle数据库操作
        /// 

        /// 数据库连接字符串
        /// DATA SOURCE=192.168.0.1:1521/mesdb;User ID=HZEVTADMIN;Password=HZEVTADMIN;
        /// 自动关闭数据库连接
        public DbHelperOracle(string strConnbool bAutoCloseConnection)
        {
            try
            {
                bAutoCloseConn = bAutoCloseConnection;
                m_Conn = new OracleConnection(strConn);
                m_Cmd = new OracleCommand();
                m_Cmd.CommandTimeout = 10;
                m_Cmd.Connection = m_Conn;
            }
            catch(Exception e)
            {
                throw e;
            }
        }
        public OracleConnection Conn
        {
            get { return m_Conn; }
        }
        public OracleCommand Cmd
        {
            get { return m_Cmd; }
        }

        /// 
        /// 通过SQL语句提交命令
        /// 

        /// 要执行的SQL语句
        /// 受影响的行数
        public int ExecDataBySql(string strSql)
        {
            int intReturnValue;
            m_Cmd.CommandType = CommandType.Text;
            m_Cmd.CommandText = strSql;
            try
            {
                if (m_Conn.State == ConnectionState.Broken || m_Conn.State == ConnectionState.Closed)
                {
                    m_Conn.Open();
                }
                intReturnValue = m_Cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if(bAutoCloseConn)
                    m_Conn.Close();
            }
            return intReturnValue;
        }

        /// 
        /// SQL语句提交数据(含事务回滚)
        /// 

        /// SQL语句(多条)
        /// bool值,提交是否成功
        public bool TranExecDataBySql(ArrayList strSqls)
        {
            bool booIsSucceed;
            if (m_Conn.State == ConnectionState.Closed || m_Conn.State == ConnectionState.Broken)
            {
                m_Conn.Open();
            }
            //创建事务
            OracleTransaction sqlTran = m_Conn.BeginTransaction();
            try
            {
                m_Cmd.Transaction = sqlTran;
                m_Cmd.CommandType = CommandType.Text;
                for (int i = 0; i < strSqls.Count; i++)
                {
            

评论

共有 条评论