Login Function of C#

  1. public bool _Login(string Username, string Password, string connection, string TableName)  
  2. {  
  3.    string _username = Username;  
  4.    string _password = Password;  
  5.    string _Query = "SELECT * FROM'"+TableName+"' WHERE Username='"+_username+"'AND Password='"+_password+"'";  
  6.    string _Connection = connection;  
  7.    SqlConnection Con = new SqlConnection(_Connection);  
  8.    Con.Open();  
  9.    SqlCommand cmd = new SqlCommand(_Query,Con);  
  10.    SqlDataReader Dr = cmd.ExecuteReader();  
  11.    while (Dr.Read())  
  12.    {  
  13.       if (_username == Dr["Username"].ToString() && _password == Dr["Password"].ToString())  
  14.          {     
  15.                return true;  
  16.          }  
  17.    }  
  18.    return false;  
  19. }