if (this.TextBox1.Text != Session["mm"].ToString()) 未将对象引用设置到对象的
usingSystem;usingSystem.Data;usingSystem.Data.OleDb;usingSystem.Configuration;usingSy...
using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class xg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.TextBox1.Text != Session["mm"].ToString())
{
this.Label6.Text = "原密码输入不正确";
}
else if (this.TextBox2.Text == this.TextBox3.Text & this.TextBox2.Text != "" & this.TextBox3.Text != "")
{
OleDbConnection coon;
OleDbCommand cmd;
coon = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;" +
"Data Source=" + MapPath("App_Data/student34.mdb"));
cmd = new OleDbCommand("update users set users.userpassword='" + this.TextBox2.Text + "'where users.username='" + Session["dlm"].ToString() + "'", coon);
coon.Open();
cmd.ExecuteNonQuery();
this.Label6.Text = "密码修改成功";
}
else
{
this.Label6.Text = "新密码确认不正确或新密码输入为空";
}
} 展开
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class xg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.TextBox1.Text != Session["mm"].ToString())
{
this.Label6.Text = "原密码输入不正确";
}
else if (this.TextBox2.Text == this.TextBox3.Text & this.TextBox2.Text != "" & this.TextBox3.Text != "")
{
OleDbConnection coon;
OleDbCommand cmd;
coon = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;" +
"Data Source=" + MapPath("App_Data/student34.mdb"));
cmd = new OleDbCommand("update users set users.userpassword='" + this.TextBox2.Text + "'where users.username='" + Session["dlm"].ToString() + "'", coon);
coon.Open();
cmd.ExecuteNonQuery();
this.Label6.Text = "密码修改成功";
}
else
{
this.Label6.Text = "新密码确认不正确或新密码输入为空";
}
} 展开
3个回答
展开全部
Session["mm"] 本身没有取到值,为空,就是null,所以使用Session["mm"]就会报错:未将对象引用设置到对象的实例
解决方法:先判断Session["mm"]不为空,再使用Session["mm"]的值
if( Session["mm"] != null)
{
if (this.TextBox1.Text != Session["mm"].ToString())
{
this.Label6.Text = "原密码输入不正确";
}
else if (this.TextBox2.Text == this.TextBox3.Text & this.TextBox2.Text != "" & this.TextBox3.Text != "")
{
OleDbConnection coon;
OleDbCommand cmd;
coon = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;" +
"Data Source=" + MapPath("App_Data/student34.mdb"));
cmd = new OleDbCommand("update users set users.userpassword='" + this.TextBox2.Text + "'where users.username='" + Session["dlm"].ToString() + "'", coon);
coon.Open();
cmd.ExecuteNonQuery();
this.Label6.Text = "密码修改成功";
}
else
{
this.Label6.Text = "新密码确认不正确或新密码输入为空";
}
}
解决方法:先判断Session["mm"]不为空,再使用Session["mm"]的值
if( Session["mm"] != null)
{
if (this.TextBox1.Text != Session["mm"].ToString())
{
this.Label6.Text = "原密码输入不正确";
}
else if (this.TextBox2.Text == this.TextBox3.Text & this.TextBox2.Text != "" & this.TextBox3.Text != "")
{
OleDbConnection coon;
OleDbCommand cmd;
coon = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;" +
"Data Source=" + MapPath("App_Data/student34.mdb"));
cmd = new OleDbCommand("update users set users.userpassword='" + this.TextBox2.Text + "'where users.username='" + Session["dlm"].ToString() + "'", coon);
coon.Open();
cmd.ExecuteNonQuery();
this.Label6.Text = "密码修改成功";
}
else
{
this.Label6.Text = "新密码确认不正确或新密码输入为空";
}
}
展开全部
你的session丢失了。你在使用session回话对象之前最好判断一下
if(Session["xxx"]!=null)
{
//然后再去使用它
}
可靠编程嘛,需要严谨点~
if(Session["xxx"]!=null)
{
//然后再去使用它
}
可靠编程嘛,需要严谨点~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if(Session["mm"]!=null)
{
if (this.TextBox1.Text != Session["mm"].ToString())
{
//将代码复制过来
}
}
{
if (this.TextBox1.Text != Session["mm"].ToString())
{
//将代码复制过来
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询