Esempio n. 1
0
        // insert professor values into db
        public static void InsertProfessor(SqlConnection conn, Professors newProfessor)
        {
            var _insert = "INSERT INTO Professors (Name, Title)" +
                          " VALUES (@Name, @Title)";
            var cmd = new SqlCommand(_insert, conn);

            cmd.Parameters.AddWithValue("Name", newProfessor.NewProfessorName);
            cmd.Parameters.AddWithValue("Title", newProfessor.NewProfessorTitle);
            cmd.ExecuteScalar();
        }
Esempio n. 2
0
        // display all professors that are in db
        public static List <Professors> GetAllProfessors(SqlConnection conn)
        {
            var _select = "SELECT [ID], [Name], [Title] FROM Professors";
            var query   = new SqlCommand(_select, conn);
            var reader  = query.ExecuteReader();
            var _rv     = new List <Professors>();

            // parse results
            while (reader.Read())
            {
                var _newProfessor = new Professors(reader);
                Console.WriteLine($"Professor's Name: {_newProfessor.NewProfessorName}, Professor's Title: {_newProfessor.NewProfessorTitle}");
            }
            reader.Close();
            return(_rv);
        }
Esempio n. 3
0
        // read for professor info
        public static Professors CreateProfessor()
        {
            Console.WriteLine("What is the Professor's name?");
            var professorNameFromInput = Console.ReadLine();

            Console.WriteLine("What is the Professor's title?");
            var professorTitleFromInput = Console.ReadLine();

            // store input values for professors
            var newProfessor = new Professors
            {
                NewProfessorName  = professorNameFromInput,
                NewProfessorTitle = professorTitleFromInput
            };

            return(newProfessor);
        }