Overblog Suivre ce blog
Editer l'article Administration Créer mon blog

Présentation

  • : Romagny13 - Du .NET,du pur .NET
  • Romagny13 - Du .NET,du pur .NET
  • : Cycle de progression Faire (quelque chose qui marche) -> comprendre ce que l’on fait/comment cela marche -> pousser plus loin les notions
  • Contact

Recherche

Articles Récents

3 février 2014 1 03 /02 /février /2014 19:04

 

Le singleton utilisé pour la connexion

public class Sql

       {

             private static Sql _instance;

             private OleDbConnection connection;

             private static object locker = new object();

             public ConnectionStringSettings ConnectionStringSettings { get; set; }

 

             private Sql() { }

 

             public static Sql Instance

             {

                    get

                    {

                           lock (locker)

                           {

                                  if (_instance == null)

                                  _instance = new Sql();

                           }

                           return _instance;

                    }

             }

 

             public OleDbConnection GetConnection()

             {

                    if (connection == null)

                    {

                           ConnectionStringSettings = ConfigurationManager.ConnectionStrings["dbConnectionString"];

                           connection = new OleDbConnection();

                    }

            connection.ConnectionString = ConnectionStringSettings.ConnectionString;

                    if (connection.State == ConnectionState.Closed)

                           connection.Open();

                    return connection;

 

             }

                                 

       }

 

La classique classe Client

public class Client          

{

        public int Id { get; set; }

        public string Name { get; set; }

        public string Email { get; set; }

        public int CategoryId { get; set; }

}

 

 

Partager cet article

Repost 0
Published by Romagny13 - dans ADO.NET
commenter cet article

commentaires