Exemple #1
0
        public void VoegKlasToe(Klas k)
        {
            SqlConnection connection = getConnection();
            string        query      = "INSERT INTO dbo.klasSQL (klasnaam) VALUES(@klasnaam)";

            using (SqlCommand command = connection.CreateCommand())
            {
                connection.Open();
                try
                {
                    command.Parameters.Add(new SqlParameter("@klasnaam", SqlDbType.NVarChar));
                    command.CommandText = query;
                    command.Parameters["@klasnaam"].Value = k.klasnaam;
                    command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Exemple #2
0
        public Klas GeefKlas(int id)
        {
            SqlConnection connection = getConnection();
            string        query      = "SELECT * FROM dbo.klasSQL WHERE id=@id";

            using (SqlCommand command = connection.CreateCommand())
            {
                command.CommandText = query;
                SqlParameter paramId = new SqlParameter();
                paramId.ParameterName = "@Id";
                paramId.DbType        = DbType.Int32;
                paramId.Value         = id;
                command.Parameters.Add(paramId);
                connection.Open();
                try
                {
                    IDataReader reader = command.ExecuteReader(); //of SqlDataReader
                    reader.Read();
                    Klas klas = new Klas((int)reader["Id"], (string)reader["klasnaam"]);
                    reader.Close();
                    return(klas);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return(null);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Exemple #3
0
 public Student(int studentId, string naam, Klas klas)
 {
     this.studentId = studentId;
     this.naam      = naam;
     this.klas      = klas;
     this.cursussen = new List <Cursus>();
 }
Exemple #4
0
        public Student GeefStudent(int id)
        {
            SqlConnection connection = getConnection();
            string        queryS     = "SELECT * FROM dbo.studentSQL WHERE id=@id";
            string        querySC    = "SELECT * FROM [dbo].[cursusSQL] t1,[dbo].[student_cursusSQL] t2 "
                                       + "where t1.Id = t2.cursusid and t2.studentid = @id";

            using (SqlCommand command = connection.CreateCommand())
            {
                command.CommandText = queryS;
                SqlParameter paramId = new SqlParameter();
                paramId.ParameterName = "@Id";
                paramId.DbType        = DbType.Int32;
                paramId.Value         = id;
                command.Parameters.Add(paramId);
                connection.Open();
                try
                {
                    SqlDataReader reader = command.ExecuteReader();
                    reader.Read();
                    int    studentId   = (int)reader["Id"];
                    string studentnaam = (string)reader["naam"];
                    int    klasId      = (int)reader["klasId"];
                    reader.Close();
                    Klas    klas    = GeefKlas(klasId);
                    Student student = new Student(studentId, studentnaam, klas);

                    command.CommandText = querySC;
                    reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        Cursus cursus = new Cursus(reader.GetInt32(0), reader.GetString(1));
                        student.voegCursusToe(cursus);
                    }
                    reader.Close();
                    return(student);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return(null);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Exemple #5
0
 public Student(string naam, Klas klas)
 {
     this.naam      = naam;
     this.klas      = klas;
     this.cursussen = new List <Cursus>();
 }