public ProfessorModel GetProfessorUser(string username) { var queryString = string.Format("SELECT Professor_Name, Professor_ID, username, password FROM Professors WHERE username = '******'", username); var professor = new ProfessorModel(); sqlConnection1.Open(); var reader = GetDatabaseResults(queryString); if (reader.HasRows) { while (reader.Read()) { var Professor_Name = reader.GetString(0); var Professor_ID = reader.GetInt32(1); var user = reader.GetString(2); var password = reader.GetString(3); professor = new ProfessorModel { Professor_Name = Professor_Name, Professor_ID = Professor_ID, username = user, password = password}; } } sqlConnection1.Close(); return professor; }
public IEnumerable<ProfessorModel> GetAllProfessors() { List<ProfessorModel> professors = new List<ProfessorModel>(); sqlConnection1.Open(); var reader = GetDatabaseResults("SELECT Professor_Name, Professor_ID FROM Professors"); if (reader.HasRows) { while (reader.Read()) { var Professor_Name = reader.GetString(0); var Professor_ID = reader.GetInt32(1); var professor = new ProfessorModel { Professor_Name = Professor_Name, Professor_ID = Professor_ID }; professors.Add(professor); } } sqlConnection1.Close(); return professors; }