DB类

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 15:48:531731Durchsuche

namespace PlasticDAL { public class DBHelper { //定义数据库链接属性 private static SqlConnection objSqlConnection; /// summary /// 获得数据库连接状态 /// /summary public static SqlConnection ObjSqlConnection { get { string DBConnectionStri

namespace PlasticDAL
{
  
    public class DBHelper
    {

        //定义数据库链接属性
        private static SqlConnection objSqlConnection;

        ///


        /// 获得数据库连接状态
        ///

        public static SqlConnection ObjSqlConnection
        {
            get
            {
                string DBConnectionString = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
                if (objSqlConnection == null)
                {
                    objSqlConnection = new SqlConnection(DBConnectionString);
                    objSqlConnection.Open();
                }
                else if (objSqlConnection.State == System.Data.ConnectionState.Closed)
                {
                    objSqlConnection.Open();
                }
                else if (objSqlConnection.State == System.Data.ConnectionState.Broken)
                {
                    objSqlConnection.Close();
                    objSqlConnection.Open();
                }
                return objSqlConnection;
            }
        }

        public static void CloseConn()
        {
            if (objSqlConnection.State==ConnectionState.Open)
            {
                objSqlConnection.Close();
            }
        }
         public static int ExecuteNonQueryBySql(string sql)
        {
            SqlCommand objSqlCommand = new SqlCommand(sql, ObjSqlConnection);
          
            return objSqlCommand.ExecuteNonQuery();
        }

         public static SqlDataReader GetReaderBySql(string sql)
        {

            SqlCommand cmd = new SqlCommand(sql, ObjSqlConnection);
            SqlDataReader reader = cmd.ExecuteReader();
            return reader;
        }

             
 
    }
}

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn