Click here to Skip to main content
15,881,588 members
Articles / Database Development / SQL Server

Provider Design Patterns in NET 2.0

Rate me:
Please Sign up or sign in to vote.
4.96/5 (14 votes)
29 Oct 2008CPOL7 min read 72.4K   1K   86  
Provider Design Pattern is a new pattern that Microsoft formalized in .NET 2 to increase application performance where there is no need to explicitly instantiate classes.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace CompanyName.PhoneBook.PhoneBookApplication
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        private void Main_Load(object sender, EventArgs e)
        {
            try
            {
                if (ConfigurationManager.ConnectionStrings["strcon"] != null)
                {
                    txtStrcon.Text = ConfigurationManager.ConnectionStrings["strcon"].ToString();
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.ToString()); }//"Can't find connection string in app.config"); }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            if (config.AppSettings.Settings["strcon"] != null)
                config.AppSettings.Settings["strcon"].Value = txtStrcon.Text.Trim();
            else
                config.AppSettings.Settings.Add("strcon", txtStrcon.Text.Trim());
            MessageBox.Show("Saved successfully", "Successfully");
        }

        private void btnAddPerson_Click(object sender, EventArgs e)
        {
            AddPerson frmAddperson = new AddPerson(true,0);
            frmAddperson.ShowDialog();
        }

        private void btnSerch_Click(object sender, EventArgs e)
        {
            AdvancedSearch frmSearch = new AdvancedSearch();
            frmSearch.ShowDialog();
        }

        private void btnManageGroups_Click(object sender, EventArgs e)
        {
            ManageGroups frmManage = new ManageGroups();
            frmManage.ShowDialog();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Egypt Egypt
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions