Configuration ASP.Net Tutorial

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"  Inherits="FromConfig" %>



    Connection String from Config


    
    

        
        
        
    

    


File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class FromConfig : System.Web.UI.Page
{
    protected void Button1_Click(object sender, EventArgs e)
    {
        string connString = ConfigurationManager.ConnectionStrings["LocalNWind"].ConnectionString;
        using (SqlConnection conn = new SqlConnection(connString))
        {
            string cmdText = "SELECT * FROM customers";
            SqlCommand cmd = new SqlCommand(cmdText, conn);
            cmd.Connection.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            CustomerList.Items.Clear();
            while (reader.Read())
                CustomerList.Items.Add(reader["companyname"].ToString());
            reader.Close();
             cmd.Connection.Close();
        }
    }
}
File: Web.config


...
  
    
  

...