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
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 && Ans == TextBox2.Text)
{
Response.Redirect("NewPassword.aspx?email="+TextBox3.Text);
}
}
but error is here
**string sq = (ds.Tables["0"]).ToString();
string Ans = (ds.Tables["1"]).ToString();**
using this code i am taking email id as query string and sending it to NewPassword.aspx
page where i can set new passsword and update this using email id for changing particular column.
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.
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();
}
}
So please provide me solution as soon as possible.
Thanks and Regards
Vasundara Reddy