title: Calling connection string from connection.cs file
body: <p>Is there any problem with the code?? Its not working and throwing an exception object ref. not set to an instance of object..
  The exception is in datageneric.cs file at codeline <em>string DbConnectionString = Connection.ConnectionString;</em></p>
  
  <p>connection.cs</p>
  
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.Configuration;
      public static class Connection
      {
      private static string constr = "server=.;database=foood;";
          public static string ConnectionString
          {
      get
      {
          return constr;
      }
      set
      {
          constr = value;
      }
  }
  public static string ProviderName { get; set; }
  static Connection()
  {
      ConnectionString =WebConfigurationManager.ConnectionStrings["constring"].ConnectionString;
      ProviderName = WebConfigurationManager.ConnectionStrings["constring"].ProviderName;
  }
      }
  </code></pre>
  
  <p>DataGeneric.cs</p>
  
  <pre><code>        public static DbCommand CreateCommand()
  {
      DbCommand cmd=null;
      try
      {
          string DbConnectionString = Connection.ConnectionString;
          string DbProviderName = Connection.ProviderName;
          DbProviderFactory factory = DbProviderFactories.GetFactory(DbProviderName);
          DbConnection conn = factory.CreateConnection();
          conn.ConnectionString = DbConnectionString;
          cmd = conn.CreateCommand();
          cmd.CommandType = CommandType.Text;
      }
      catch (Exception ex) { }
      return cmd;
  }
  </code></pre>
  
  <p>GetData.cs</p>
  
  <pre><code>        public static DataTable gimmedata()
  {
      string Query = "select * from [slider]";
      DbCommand cmd = DataGeneric.CreateCommand();
      cmd.CommandText = Query;
      DataTable dt = DataGeneric.ExecuteSelectCommand(cmd);
      return dt;
  }
  </code></pre>
  
  <p>Default.aspx.cs</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      DataTable dt = GetData.gimmedata();
      GridView1.DataSource = dt;
      GridView1.DataBind();
  
  }
  </code></pre>