关于修改密码
如下:我修改密码,有原密码、新密码、确定新密码三个textbox,看看下面代码怎么啦???没反应!求求!!!
protected void Page_Load(object sender, EventArgs e)
{
String username = Session["UserName"].ToString();
Label2.Text = username;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
try
{
SqlConnection conn = new SqlConnection();
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select Password from [USER] where User_Name = '" + Label2.Text + "'";
cmd.Connection = conn;
conn.Open();
string s=cmd.ExecuteNonQuery().ToString();
// SqlDataReader myReader = cmd.ExecuteReader();
// string s = (string)myReader["Password"];
//Response.Write(s);
conn.Close();
if (s == TextBox1.Text)
{
SqlConnection con = new SqlConnection();
con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand cd = new SqlCommand();
cmd.CommandText = "Update [USER] set Password='" + TextBox2.Text + "' where User_Name='" + Label2.Text + "'";
cmd.Connection = con;
con.Open();
cd.ExecuteNonQuery();
con.Close();
}
else
{
Label3.Text = "原密码错误";
}
}
catch (Exception ee) { Response.Write(ee); }
} --------------------编程问答-------------------- 我晕,你这代码写得太丑。
你这里出错了
cmd.CommandText = "Update [USER] set Password='" + TextBox2.Text + "' where User_Name='" + Label2.Text + "'";
cmd.Connection = con;
换成:
cd.CommandText = "Update [USER] set Password='" + TextBox2.Text + "' where User_Name='" + Label2.Text + "'";
cd.Connection = con;
--------------------编程问答-------------------- 先判断 旧密码符合不符合
如果符合 判断后面那两个文本框想等就可以更新了。 --------------------编程问答-------------------- 你new了两个SqlCommand 你第二个的对象名叫cd,你居然还用第一个的对象名cmd。还有就是,你干嘛要new两个。。。。。其次,你的Page_Load中间建议修改为
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
String username = Session["UserName"].ToString();
Label2.Text = username;
}
}
--------------------编程问答-------------------- 不是初学嘛!!! --------------------编程问答--------------------
你是否调试成功了?如果调试成功,别忘了结贴啊 --------------------编程问答-------------------- 结贴给分 喵~
补充:.NET技术 , ASP.NET