title: Object reference not set to an instance of an object error flags when running webform
body: <p>I'm trying to search my database to retrieve some results and populate those to a gridview.</p>
  
  <p>However, I get the above error in the title, and some research hasn't really helped me on why this kind of error flags, and was wondering whether someone with a sharper mind could explain the reason for this error. My code for the code behind file of the specific page is shown below:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Data;
  using System.Data.SqlClient;
  using System.Configuration;
  
  namespace StarksComics
  {
      public partial class search : System.Web.UI.Page
      {
  
          SqlConnection con = new SqlConnection();
          string b = "";
  
  
          protected void Page_Load(object sender, EventArgs e)
          {
              con.ConnectionString = ConfigurationManager.ConnectionStrings["DBVS"].ConnectionString; // the error occurs at this line. ---- nullreference exception was unhandled by code.
  
              if (con.State == ConnectionState.Closed)
              {
                  con.Open();
              }
  
          }
  
          private void user_chk()
          {
              string a;
              a = TextBox1.Text;
  
              SqlCommand cmd = new SqlCommand();
              cmd.CommandText = "select * from tbCharacters where CharName like'" + a + "%'";
              cmd.Connection = con;
  
              SqlDataReader dr;
              dr = cmd.ExecuteReader();
              if (dr.HasRows)
              {
                  dr.Read();
                  rep_bind();
                  GridView1.Visible = true;
  
                  TextBox1.Text = "";
  
              }
              else
              {
                  GridView1.Visible = false;
                  b = TextBox1.Text + "is not available in list";
                  TextBox1.Text="";
              }
          }
  
          private void rep_bind()
          {
              string a;
              a = TextBox1.Text;
              SqlDataAdapter adp = new SqlDataAdapter("select * from tbCharacters where CharName like'" + a + "%'",
                  ConfigurationManager.ConnectionStrings["DBVS"].ConnectionString);
              DataSet ds = new DataSet();
              adp.Fill(ds);
              GridView1.DataSource = ds;
              GridView1.DataBind();
          }
  
          protected void Button1_Click(object sender, EventArgs e)
          {
              user_chk();
          }
      }
  
  }
  </code></pre>
  
  <p>once again, thank you all kindly for reviewing my code. (I've commented out the line, it's just not visible unless you drag the bar, in the page load method.)</p>