Response.Redirect(" ****。aspx");

时间:2014-10-15 04:18:06

标签: asp.net

当我输入错误的用户名和密码时,它不会转到 error.aspx (表单)。 这是我的代码:

protected void Button1_Click(object sender, EventArgs e)
{

    SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\1\Documents\DB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
    conn.Open();
    string checkuser = "select count(*) from [Users] where Username '" + TextBoxUserName.Text + "'";
    SqlCommand com = new SqlCommand(checkuser,conn);
    int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
    conn.Close();

    if (temp == 1)
    {
        conn.Open();
        string checkpassword = "select Password from Users where Password'" + TextBoxPassword.Text + "'";
        SqlCommand passComm = new SqlCommand(checkpassword, conn);
        string password = passComm.ExecuteScalar().ToString();
        if (password == TextBoxPassword.Text)
        {
            //Session["NEW"] = TextBoxUserName.Text;
            Response.Redirect("Welcome.aspx");
        }
        **else
          if (password != TextBoxPassword.Text)
          {
              Response.Redirect("Error.aspx");
          }**
  }

它给我一个错误"Object reference not set to an instance of an object" in this line of code: string password = passComm.ExecuteScalar().ToString();

0 个答案:

没有答案