Exemplo n.º 1
0
        public void AddStudent(University student)
        {
            try
            {
                connection.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = connection;
                cmd.CommandText = "INSERT INTO student (studentName,studentLastName,studentCours) " +
                                  "VALUES(@studentName,@studentLastname,@studentCours)";

                cmd.Prepare();
                cmd.Parameters.AddWithValue("@studentName", student.getName());
                cmd.Parameters.AddWithValue("@studentLastName", student.getLastName());
                cmd.Parameters.AddWithValue("@studentCours", student.getCours());
                cmd.ExecuteNonQuery();
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
        }
Exemplo n.º 2
0
        public static void AddStudent(DBConnection con)
        {
            Console.WriteLine();
            Console.WriteLine("----------------------------");

            string name     = "";
            string lastName = "";
            int    cours    = 0;

            bool b1;
            bool b2;

            Console.WriteLine("Enter name:");
            name = Console.ReadLine();

            if (b1 = string.IsNullOrWhiteSpace(name))
            {
                Console.WriteLine("Please enter students name!");
                b1 = false;
            }
            else
            {
                b1 = true;
            }

            if (b1 == true)
            {
                Console.WriteLine("Enter last name:");
                lastName = Console.ReadLine();

                if (b2 = string.IsNullOrWhiteSpace(lastName))
                {
                    Console.WriteLine("Please enter students last name!");
                    b2 = false;
                }
                else
                {
                    b2 = true;
                }

                if (b2 == true)
                {
                    Console.WriteLine("Enter Cours:");
                    string coursString = Console.ReadLine();

                    try
                    {
                        cours = Convert.ToInt32(coursString);

                        University student = new University(name, lastName, cours);

                        con.AddStudent(student);

                        Console.WriteLine("----------------------------");
                        Console.WriteLine();
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Please enter student cours with numbers");
                        AddStudent(con);
                        return;
                    }
                }
                else
                {
                    AddStudent(con);
                    return;
                }
            }
            else
            {
                AddStudent(con);
                return;
            }
        }