没有设置为一个对象的实例的错误,即对象的引用,我试图来比较安全性问题,并使用电子邮件ID是存在于数据库中使用下面 代码错误:未将对象引用设置为对象的实例?
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);
}
}
但错误是在这里回答
**string sq = (ds.Tables["0"]).ToString();
string Ans = (ds.Tables["1"]).ToString();**
使用此代码我以电子邮件ID作为查询字符串,并将其发送给NewPassword.aspx
页面,在这里我可以设置新密码时应并更新此使用电子邮件ID为改变特定列。
和NewPassword.aspx代码有一个按钮,在一个按钮上单击新密码应该在我的数据库的注册表和登录表中更新。
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();
}
}
请尽快提供给我解决方案。
感谢和问候
Vasundara雷迪
可能重复[什么是NullReferenceException,我该如何解决它?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – nvoigt