为什么我的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。不执行下面的句子。
展开
 我来答
koujiang901123
2012-05-13 · 超过34用户采纳过TA的回答
知道答主
回答量:140
采纳率:0%
帮助的人:75.7万
展开全部
if语句的类容你确定是1?
""中是没有值的吧!你是想其中为空格?
如果是空格就应该是" "在中间加个空格。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友6a40d632534
2012-05-20 · 超过13用户采纳过TA的回答
知道答主
回答量:31
采纳率:0%
帮助的人:28.8万
展开全部
你debug
password == pa
两边是什么以看不就知道为什么了么?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式