title: Syntax Error with Database Login System
body: <p>Created a website login system but when I run it it keeps coming up with this error to the particular bit of coding below. Can someone PLEASE help me with this Error message on this particular code:</p>
  
  <blockquote>
    <p>System.Data.SqlClient.SqlException: Incorrect syntax near the keyword
    'user'.</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>  public static User LoginUser(string login, string password)
      {
          //Check if user exists
          string query = string.Format("SELECT COUNT(*) FROM TeesDB.dbo.user WHERE name = '{0}'",
           login);
          command.CommandText = query;
  
          try
          {
              conn.Open();
              int amountOfUsers = (int) command.ExecuteScalar();
  
              if(amountOfUsers == 1)
              {
                  //User exists, check if the password match
                  query = string.Format("SELECT password FROM users WHERE name = '{0}", login);
                  command.CommandText = query;
                  string dbPassword = command.ExecuteScalar().ToString();
  
  
                  if (dbPassword == password)
                  {
                      //password match. Login and password data are known to us.
                      //retrieve further user data from the database
                      query = string.Format("SELECT email, user_type FROM users WHERE name =
                        '{0}'", login);
                      command.CommandText = query;
  
                      SqlDataReader reader = command.ExecuteReader();
                      User user = null;
  
                      while (reader.Read())
                      {
                          string email = reader.GetString(0);
                          string type = reader.GetString(1);
  
                          user = new User(login, password, email, type);
                      }
                      return user;
                  }
                  else
                  {
  
                      //passwords do not match
                      return null;
  
                  }
  
              }
              else
              {
  
                  //user exists
                  return null;
  
              }
          }
          finally
          {
  
              conn.Close();
           }
         }
        }
       }
  </code></pre>