沒有設置爲一個對象的實例的錯誤,即對象的引用,我試圖來比較安全性問題,並使用電子郵件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