title: ASP.NET Login in n-tier architecture
body: <p>I'm trying to implement login functionality in ASP.NET C# based on n-tier architecture.</p>
  
  <p>Data access:</p>
  
  <pre><code>public int userlogin(string user, string passw)//checking the user name and password
  {
      SqlConnection con = new SqlConnection();
      con.ConnectionString = GetConnectionString();
      con.Open();
      int id = 0;
      string selectstr = "SELECT NurseName, password FROM Nurse2 WHERE NurseName = '" + user.Trim() + "' AND Password = '" + passw.Trim() + "'";
      SqlCommand cmd = new SqlCommand();
      cmd.CommandText = selectstr;
      cmd.CommandType = System.Data.CommandType.Text;
      cmd.Connection = con;
      SqlDataReader reader = cmd.ExecuteReader();
      while (reader.Read())
      {
          id++;
      }
      cmd = null;
      reader.Close();
      con.Close();
      return id;
  }
  </code></pre>
  
  <p>Presentation layer .cs file</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
      string name = TextBox1.Text;
        string password = TextBox2.Text;
      int id = da.userlogin(name, password);
      if (id &gt; 0)
      {
          Session["userName"] = name;
  
          Response.Redirect("SubscribePage.aspx");
  
      }
      else
      {
          Label1.Text = "invalid";
      }
  </code></pre>
  
  <p>Now, my issue is when I press button the program simply goes to else clause, even though I enter correct data. What could be possibly not OK here as to me it all seems fine.</p>