为什么我的if语句总是执行else,不执行if下面的语句? 5
usingSystem;usingSystem.Collections;usingSystem.ComponentModel;usingSystem.Data;using...
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class updatepassword : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
string password;
string newpassword;
string ww;
ww = TextBox3.Text;
newpassword = TextBox2.Text;
string EnPswdStr = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text.ToString(), "MD5");
password = EnPswdStr;
if (ww == "" || newpassword == "" || password == "")
{
Response.Write("<script language='JavaScript'>");
Response.Write("alert('密码不能为空!')");
Response.Write("</script>");
return;
}
string sqlconn = ConfigurationManager.ConnectionStrings["wylConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(sqlconn);
conn.Open();
String cmd = "SELECT Password FROM RegisterUser where UserName='" + Session["username"].ToString() + "'";
SqlCommand mycommand = new SqlCommand(cmd, conn);
string pa = mycommand.ExecuteScalar().ToString();
if (password == pa)
{
string ENnew = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text.ToString(), "MD5");
string ccmd = "update RegisterUser SET Password='" + ENnew + "' where UserName='" + Session["username"].ToString() + "' ";
SqlCommand mycommand1 = new SqlCommand(ccmd, conn);
mycommand1.ExecuteNonQuery();
Response.Write("<script language='JavaScript'>");
Response.Write("alert('修改密码成功!')");
Response.Write("</script>");
//Response.Redirect("useManage.aspx");
}
else
{
Response.Write("<script language='JavaScript'>");
Response.Write("alert(原密码不正确!')");
Response.Write("</script>");
}
conn.Close();
}
}
if (password == pa)
{
string ENnew = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text.ToString(), "MD5");
string ccmd = "update RegisterUser SET Password='" + ENnew + "' where UserName='" + Session["username"].ToString() + "' ";
SqlCommand mycommand1 = new SqlCommand(ccmd, conn);
mycommand1.ExecuteNonQuery();
Response.Write("<script language='JavaScript'>");
Response.Write("alert('修改密码成功!')");
Response.Write("</script>");
//Response.Redirect("useManage.aspx");
}
else
{
Response.Write("<script language='JavaScript'>");
Response.Write("alert(原密码不正确!')");
Response.Write("</script>");
}
conn.Close();
}
}
这个语句总是执行else。不执行下面的句子。 展开
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class updatepassword : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
string password;
string newpassword;
string ww;
ww = TextBox3.Text;
newpassword = TextBox2.Text;
string EnPswdStr = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text.ToString(), "MD5");
password = EnPswdStr;
if (ww == "" || newpassword == "" || password == "")
{
Response.Write("<script language='JavaScript'>");
Response.Write("alert('密码不能为空!')");
Response.Write("</script>");
return;
}
string sqlconn = ConfigurationManager.ConnectionStrings["wylConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(sqlconn);
conn.Open();
String cmd = "SELECT Password FROM RegisterUser where UserName='" + Session["username"].ToString() + "'";
SqlCommand mycommand = new SqlCommand(cmd, conn);
string pa = mycommand.ExecuteScalar().ToString();
if (password == pa)
{
string ENnew = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text.ToString(), "MD5");
string ccmd = "update RegisterUser SET Password='" + ENnew + "' where UserName='" + Session["username"].ToString() + "' ";
SqlCommand mycommand1 = new SqlCommand(ccmd, conn);
mycommand1.ExecuteNonQuery();
Response.Write("<script language='JavaScript'>");
Response.Write("alert('修改密码成功!')");
Response.Write("</script>");
//Response.Redirect("useManage.aspx");
}
else
{
Response.Write("<script language='JavaScript'>");
Response.Write("alert(原密码不正确!')");
Response.Write("</script>");
}
conn.Close();
}
}
if (password == pa)
{
string ENnew = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text.ToString(), "MD5");
string ccmd = "update RegisterUser SET Password='" + ENnew + "' where UserName='" + Session["username"].ToString() + "' ";
SqlCommand mycommand1 = new SqlCommand(ccmd, conn);
mycommand1.ExecuteNonQuery();
Response.Write("<script language='JavaScript'>");
Response.Write("alert('修改密码成功!')");
Response.Write("</script>");
//Response.Redirect("useManage.aspx");
}
else
{
Response.Write("<script language='JavaScript'>");
Response.Write("alert(原密码不正确!')");
Response.Write("</script>");
}
conn.Close();
}
}
这个语句总是执行else。不执行下面的句子。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询