ASP.NET中修改密码并写入数据库操作,下列代码哪里错误??
protectedvoidButton1_Click(objectsender,EventArgse){stringpw=this.TextBox1.Text;strin...
protected void Button1_Click(object sender, EventArgs e)
{
string pw = this.TextBox1.Text;
string name = Session["user_login"].ToString();
SqlConnection thisconnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\QZZP_Data.MDF;Integrated Security=True;User Instance=True");
thisconnection.Open();
SqlCommand thiscommand = thisconnection.CreateCommand();
thiscommand.CommandText = "select password from [user_basic_information] where user_login='"+name+"'";
SqlDataReader thisreader = thiscommand.ExecuteReader();
if (thisreader.Read())
{
if (password == pw)
date_update();
else
{
this.TextBox1.Text = "";
Label6.Visible = true;
Label6.Text = "您输入的密码错误!";
this.TextBox2.Text = "";
this.TextBox3.Text = "";
}
}
thisreader.Close();
thisconnection.Close();
}
protected void date_update()
{
string name = Session["user_login"].ToString();
SqlConnection thisconnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\QZZP_Data.MDF;Integrated Security=True;User Instance=True");
thisconnection.Open();
string Comstr = "update user_basic_information set password=pw where user_login='" + name + "'";
SqlCommand com = new SqlCommand(Comstr, thisconnection);
Label6.Visible = false;
thisconnection.Close();
Response.Write("<script>window.parent.location.href='person logon.aspx'</script>");
Response.End();
} 展开
{
string pw = this.TextBox1.Text;
string name = Session["user_login"].ToString();
SqlConnection thisconnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\QZZP_Data.MDF;Integrated Security=True;User Instance=True");
thisconnection.Open();
SqlCommand thiscommand = thisconnection.CreateCommand();
thiscommand.CommandText = "select password from [user_basic_information] where user_login='"+name+"'";
SqlDataReader thisreader = thiscommand.ExecuteReader();
if (thisreader.Read())
{
if (password == pw)
date_update();
else
{
this.TextBox1.Text = "";
Label6.Visible = true;
Label6.Text = "您输入的密码错误!";
this.TextBox2.Text = "";
this.TextBox3.Text = "";
}
}
thisreader.Close();
thisconnection.Close();
}
protected void date_update()
{
string name = Session["user_login"].ToString();
SqlConnection thisconnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\QZZP_Data.MDF;Integrated Security=True;User Instance=True");
thisconnection.Open();
string Comstr = "update user_basic_information set password=pw where user_login='" + name + "'";
SqlCommand com = new SqlCommand(Comstr, thisconnection);
Label6.Visible = false;
thisconnection.Close();
Response.Write("<script>window.parent.location.href='person logon.aspx'</script>");
Response.End();
} 展开
2个回答
展开全部
你这代码没有执行sql语句阿。。
在 SqlCommand com = new SqlCommand(Comstr, thisconnection);
添加: com.ExecuteNonQuery();
应该就可以了
在 SqlCommand com = new SqlCommand(Comstr, thisconnection);
添加: com.ExecuteNonQuery();
应该就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在 SqlCommand com = new SqlCommand(Comstr, thisconnection);
下面添加:com.ExecuteNonQuery();
"update user_basic_information set password=pw where user_login='" + name + "'";
把password设为pw?是不是应该带个pw参数进来。然后
date_update(string pw)
"update user_basic_information set password=“+pw+" where user_login='" + name + "'";
下面添加:com.ExecuteNonQuery();
"update user_basic_information set password=pw where user_login='" + name + "'";
把password设为pw?是不是应该带个pw参数进来。然后
date_update(string pw)
"update user_basic_information set password=“+pw+" where user_login='" + name + "'";
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询