久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

SQLHelper(中文注釋)

 liuyci 2010-11-06

using System;

using System.Collections.Generic;

using System.Data;

using System.Data.OleDb;

using System.Data.SqlClient;

namespace GeneralLibrary.DbAccess

{

    /// <summary>數(shù)據(jù)庫(kù)訪問(wèn),支持 SQL Server,、Access 數(shù)據(jù)庫(kù),。</summary>

    public class SQLHelper

    {

        private IDbCommand _DbCommand;

        private IDbDataAdapter _DbDataAdapter;

        private IDbTransaction _DbTransaction;

        /// <summary>數(shù)據(jù)庫(kù)訪問(wèn)類,。</summary>

        public SQLHelper()

        {

            if (DbConfig.DbConnection == "" || DbConfig.DbConnection == null)

            {

                throw new Exception("鏈接字符串不能為空!");

            }

            switch (DbConfig.DbType)

            {

                case DbType.Access:

                    this._DbCommand = new OleDbCommand();

                    this._DbCommand.Connection = new OleDbConnection(DbConfig.DbConnection);

                    this._DbDataAdapter = new OleDbDataAdapter();

                    break;

                case DbType.SQLServer:

                    this._DbCommand = new SqlCommand();

                    this._DbCommand.Connection = new SqlConnection(DbConfig.DbConnection);

                    this._DbDataAdapter = new SqlDataAdapter();

                    break;

            }

        }

        /// <summary>數(shù)據(jù)庫(kù)訪問(wèn)類,。</summary>

        public SQLHelper(string strConn, DbType dbtype)

        {

            switch (dbtype)

            {

                case DbType.Access:

                    this._DbCommand = new OleDbCommand();

                    this._DbCommand.Connection = new OleDbConnection(strConn);

                    this._DbDataAdapter = new OleDbDataAdapter();

                    break;

                case DbType.SQLServer:

                    this._DbCommand = new SqlCommand();

                    this._DbCommand.Connection = new SqlConnection(strConn);

                    this._DbDataAdapter = new SqlDataAdapter();

                    break;

            }

        }

        /// <summary>打開(kāi)數(shù)據(jù)庫(kù)連接,。</summary>

        private void OpenConnection()

        {

            try

            {

                if (this._DbCommand.Connection.State == ConnectionState.Closed)

                {

                    this._DbCommand.Connection.Open();

                }

            }

            catch (Exception dbex)

            {

                throw new Exception(dbex.Message);

            }

        }

        /// <summary>關(guān)閉數(shù)據(jù)庫(kù)連接。</summary>

        private void CloseConnection()

        {

            if (this._DbCommand.Connection.State == ConnectionState.Open)

            {

                this._DbCommand.Connection.Close();

            }

            if (this._DbCommand != null)

            {

                this._DbCommand.Dispose();

            }

        }

        /// <summary>執(zhí)行 SQL 語(yǔ)句,。</summary>

        /// <param name="cmdText">SQL 語(yǔ)句</param>

        /// <returns>返回影響行數(shù)</returns>

        public int ExecuteSql(string cmdText)

        {

            try

            {

                this._DbCommand.CommandText = cmdText;

                this.OpenConnection();

                return this._DbCommand.ExecuteNonQuery();

            }

            catch (Exception ex)

            {

                this.CloseConnection();

                throw new Exception(ex.Message);

            }

            finally

            {

                this.CloseConnection();

            }

        }

        /// <summary>執(zhí)行 SQL 語(yǔ)句,。</summary>

        /// <param name="cmdText">SQL 語(yǔ)句</param>

        /// <param name="cmdParameters">參數(shù)</param>

        /// <returns>返回影響行數(shù)</returns>

        public int ExecuteSql(string cmdText, IDataParameter[] cmdParameters)

        {

            try

            {

                this._DbCommand.CommandText = cmdText;

                foreach (IDataParameter parm in cmdParameters)

                {

                    this._DbCommand.Parameters.Add(parm);

                }

                this.OpenConnection();

                return this._DbCommand.ExecuteNonQuery();

            }

            catch (Exception ex)

            {

                this.CloseConnection();

                throw new Exception(ex.Message);

            }

            finally

            {

                this.CloseConnection();

            }

        }

        /// <summary>執(zhí)行 SQL 語(yǔ)句。</summary>

        /// <param name="cmdText">SQL 語(yǔ)句</param>

        /// <param name="dt">返回查詢結(jié)果</param>

        public void ExecuteSql(string cmdText, out DataTable dt)

        {

            try

            {

                this._DbCommand.CommandText = cmdText;

                this._DbDataAdapter.SelectCommand = this._DbCommand;

                DataSet ds = new DataSet();

                this._DbDataAdapter.Fill(ds);

                dt = ds.Tables[0];

            }

            catch (Exception ex)

            {

                this.CloseConnection();

                throw new Exception(ex.Message);

            }

        }

        /// <summary>執(zhí)行 SQL 語(yǔ)句,。</summary>

        /// <param name="cmdText">SQL 語(yǔ)句</param>

        /// <param name="cmdParameters">參數(shù)</param>

        /// <param name="dt">返回查詢結(jié)果</param>

        public void ExecuteSql(string cmdText, IDataParameter[] cmdParameters, out DataTable dt)

        {

            try

            {

                this._DbCommand.CommandText = cmdText;

                foreach (IDataParameter parm in cmdParameters)

                {

                    this._DbCommand.Parameters.Add(parm);

                }

                this._DbDataAdapter.SelectCommand = this._DbCommand;

                DataSet ds = new DataSet();

                this._DbDataAdapter.Fill(ds);

                dt = ds.Tables[0];

            }

            catch (Exception ex)

            {

                this.CloseConnection();

                throw new Exception(ex.Message);

            }

        }

        /// <summary>執(zhí)行存儲(chǔ)過(guò)程。</summary>

        /// <param name="procName">存儲(chǔ)過(guò)程名</param>

        /// <returns>返回影響行數(shù)</returns>

        public int ExecuteProc(string procName)

        {

            try

            {

                this._DbCommand.CommandText = procName;

                this._DbCommand.CommandType = CommandType.StoredProcedure;

                this.OpenConnection();

                return this._DbCommand.ExecuteNonQuery();

            }

            catch (Exception ex)

            {

                this.CloseConnection();

                throw new Exception(ex.Message);

            }

            finally

            {

                this.CloseConnection();

            }

        }

        /// <summary>執(zhí)行存儲(chǔ)過(guò)程,。</summary>

        /// <param name="procName">存儲(chǔ)過(guò)程名</param>

        /// <param name="cmdParameters">參數(shù)</param>

        /// <returns>返回影響行數(shù)</returns>

        public int ExecuteProc(string procName, IDataParameter[] cmdParameters)

        {

            try

            {

                this._DbCommand.CommandText = procName;

                this._DbCommand.CommandType = CommandType.StoredProcedure;

                foreach (IDataParameter parm in cmdParameters)

                {

                    this._DbCommand.Parameters.Add(parm);

                }

                this.OpenConnection();

                return this._DbCommand.ExecuteNonQuery();

            }

            catch (Exception ex)

            {

                this.CloseConnection();

                throw new Exception(ex.Message);

            }

            finally

            {

                this.CloseConnection();

            }

        }

        /// <summary>執(zhí)行存儲(chǔ)過(guò)程。</summary>

        /// <param name="procName">存儲(chǔ)過(guò)程名</param>

        /// <param name="dt">返回查詢結(jié)果</param>

        public void ExecuteProc(string procName, out DataTable dt)

        {

            try

            {

                this._DbCommand.CommandText = procName;

                this._DbCommand.CommandType = CommandType.StoredProcedure;

                this._DbDataAdapter.SelectCommand = this._DbCommand;

                DataSet ds = new DataSet();

                this._DbDataAdapter.Fill(ds);

                dt = ds.Tables[0];

            }

            catch (Exception ex)

            {

                this.CloseConnection();

                throw new Exception(ex.Message);

            }

        }

        /// <summary>執(zhí)行存儲(chǔ)過(guò)程,。</summary>

        /// <param name="procName">存儲(chǔ)過(guò)程名</param>

        /// <param name="cmdParameters">參數(shù)</param>

        /// <param name="dt">返回查詢結(jié)果</param>

        public void ExecuteProc(string procName, IDataParameter[] cmdParameters, out DataTable dt)

        {

            try

            {

                this._DbCommand.CommandText = procName;

                this._DbCommand.CommandType = CommandType.StoredProcedure;

                foreach (IDataParameter parm in cmdParameters)

                {

                    this._DbCommand.Parameters.Add(parm);

                }

                this._DbDataAdapter.SelectCommand = this._DbCommand;

                DataSet ds = new DataSet();

                this._DbDataAdapter.Fill(ds);

                dt = ds.Tables[0];

            }

            catch (Exception ex)

            {

                this.CloseConnection();

                throw new Exception(ex.Message);

            }

        }

        /// <summary>執(zhí)行事務(wù),。</summary>

        /// <param name="cmdTexts">SQL 語(yǔ)句</param>

        /// <returns></returns>

        public bool ExecuteTransaction(string[] cmdTexts)

        {

            try

            {

                this.OpenConnection();

                this._DbTransaction = this._DbCommand.Connection.BeginTransaction();

                this._DbCommand.Transaction = this._DbTransaction;

                foreach (string cmdText in cmdTexts)

                {

                    this._DbCommand.CommandText = cmdText;

                    this._DbCommand.ExecuteNonQuery();

                }

                this._DbTransaction.Commit();

            }

            catch

            {

                this._DbTransaction.Rollback();

                this.CloseConnection();

                return false;//執(zhí)行失敗

            }

            return true;//執(zhí)行成功

        }

        /// <summary>執(zhí)行事務(wù)。</summary>

        /// <param name="cmdTexts">SQL 語(yǔ)句。</param>

        /// <param name="lstParameter">參數(shù)</param>

        /// <param name="count">次數(shù)</param>

        /// <returns></returns>

        public bool ExecuteTransaction(string[] cmdTexts, List<IDataParameter[]> lstParameter, int count)

        {

            try

            {

                this.OpenConnection();

                this._DbTransaction = this._DbCommand.Connection.BeginTransaction();

                this._DbCommand.Transaction = this._DbTransaction;

                for (int i = 0; i < count; i++)

                {

                    this._DbCommand.CommandText = cmdTexts[i];

                    foreach (IDataParameter parm in lstParameter[i])

                    {

                        this._DbCommand.Parameters.Add(parm);

                    }

                    this._DbCommand.ExecuteNonQuery();

                }

                this._DbTransaction.Commit();

            }

            catch

            {

                this._DbTransaction.Rollback();

                this.CloseConnection();

                return false;//執(zhí)行失敗

            }

            return true;

        }

    }

}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購(gòu)買等信息,,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào),。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多