C#,如果条件正常工作,但其他不工作?

时间:2018-10-26 17:13:49

标签: c#

在这里,我尝试将用户ID密码与数据库匹配。
if部分运行正常,而else在浏览器中运行。
代码如下:

SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ITD_ClientConnectionString"].ConnectionString);
connection.Open();
string checku = "select count(*) from UserRG where Pan = '" + txtid.Text + "' AND Pass='"+txtpasslog.Text+"' ";

SqlCommand cdm = new SqlCommand(checku, connection);
int temp = Convert.ToInt32(cdm.ExecuteScalar().ToString());
if (temp == 1)
{
    Response.Write("<script>alert('hurry ! welcome user')</script>");
}
else { Response.Write("<script>alert('password doesn't match')</script>"); }

1 个答案:

答案 0 :(得分:1)

问题必须来自'password doesn't match'

您应该尝试

'password doesn\'t match'或更可能"password doesn't match"

或找到一种方法来摆脱中间的'