title: How to create login form in asp.net using a stored procedure?
body: <p>I am new to coding and asp.net can any one help me I am trying to create user login using a stored procedure but I'm getting an error.</p>
  
  <p>I am posting my code with error please check and help me. Thanks</p>
  
  <p>Code for data access :</p>
  
  <pre><code>public class DataAcc
  {
      SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
  
      public DataSet DA_Bind()
      {
          SqlCommand cmd = new SqlCommand("Sp_select", con);
  
          SqlDataAdapter da = new SqlDataAdapter(cmd);
          DataSet ds = new DataSet();
          da.Fill(ds);
          return ds;
      }
  }
  </code></pre>
  
  <p>Business logic code:</p>
  
  <pre><code>public class business
  {
      SqlCommand cmd = new SqlCommand();
      DataAcc sda = new DataAcc();
  
      public int id { get; set; }
      public string UserName { get; set; }
      public string Password { get; set; }
  
      public bool getuser()
      {
          if(sda.DA_Bind().Tables[0].Rows.Count==0)
          {
              cmd.Parameters.AddWithValue("@UseName", UserName);
              cmd.Parameters.AddWithValue("@Passwors", Password);
              return false;
          }
          else
          {
              return true;
          }
      }
  }  
  </code></pre>
  
  <p>Login page code</p>
  
  <pre><code>public partial class login : System.Web.UI.Page
  {
      protected void btnSave_Click(object sender, EventArgs e)
      {
          business obj = new business();
          obj.UserName = txtUser.Text;
          obj.Password = txtEmail.Text;
  
          if(obj.getuser())
          {
              Session["User"] = obj.UserName;
              Response.Redirect("mainpage.aspx");
          }
          else
          {
              Response.Redirect("Please enter correct username and password");
          }
      }
   }
  </code></pre>
  
  <p>Stored procedure:</p>
  
  <pre><code>Alter procedure Sp_select
      (@UserName varchar(50),
       @Password varchar(50))
  AS 
  BEGIN
      Select * 
      from tb_login 
      where UserName = @UserName 
        and Password = @Password
  END
  </code></pre>