title: Error:Object reference not set to an instance of an object?
body: <p>There is an error i.e. Object reference not set to an instance of an object, i am trying to compare security question and answer using email id which are present in database using below
  code</p>
  
  <pre><code>    protected void Button1_Click(object sender, EventArgs e)
  
  {
  
  SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\keishna\Documents\Visual Studio 2010\Projects\MasterDemo\App_Data\Earth_Movers.mdf;Integrated Security=True;User Instance=True");
          con.Open();
          DataSet ds = new DataSet();
          SqlCommand cmd = new SqlCommand("SELECT Security_Question,Answer FROM Registration Where email='" + TextBox3.Text + "'", con);
          SqlDataAdapter da = new SqlDataAdapter(cmd);
          da.Fill(ds,"data");
          //string Ans = (cmd.ExecuteReader()).ToString();
          string sq = (ds.Tables["0"]).ToString();
          string Ans = (ds.Tables["1"]).ToString();
          if (sq == TextBox3.Text &amp;&amp; Ans == TextBox2.Text)
          {
              Response.Redirect("NewPassword.aspx?email="+TextBox3.Text);
          }
      }
  </code></pre>
  
  <p>but error is here</p>
  
  <pre><code>**string sq = (ds.Tables["0"]).ToString();
              string Ans = (ds.Tables["1"]).ToString();**
  </code></pre>
  
  <p>using this code i am taking email id as query string and sending it to <code>NewPassword.aspx</code> page where i can set new passsword and update this using email id for changing particular column.</p>
  
  <p>and NewPassword.aspx code has a button,on a button click new password should get updated in registration table and login table of my database.</p>
  
  <pre><code>NewPassword.aspx 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.SqlClient;
  
  public partial class Webpages_NewPassword : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      { 
  
      }
      protected void Button1_Click(object sender, EventArgs e)
      {
  
          SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\krishna\Documents\Visual Studio 2010\Projects\MasterDemo\App_Data\Earth_Movers.mdf;Integrated Security=True;User Instance=True");
          con.Open();
          if (Request.QueryString["email"] != null)
          {
              string Email= Request.QueryString["email"];
              SqlCommand cmd = new SqlCommand("update Registration set Password where email='" + Email + "'", con);
          }
          con.Close();
  
      }
  }
  </code></pre>
  
  <p>So please provide me solution as soon as possible.</p>
  
  <p>Thanks and Regards</p>
  
  <p>Vasundara Reddy</p>