public Student(int studentId, string naam, Klas klas) { this.studentId = studentId; this.naam = naam; this.klas = klas; this.cursussen = new List <Cursus>(); }
public void VoegKlasToe(Klas k) { DbConnection connection = getConnection(); string query = "INSERT INTO dbo.klas (klasnaam) VALUES(@klasnaam)"; using (DbCommand command = connection.CreateCommand()) { connection.Open(); try { DbParameter parNaam = sqlFactory.CreateParameter(); parNaam.ParameterName = "@klasnaam"; parNaam.DbType = DbType.String; command.Parameters.Add(parNaam); command.CommandText = query; command.Parameters["@klasnaam"].Value = k.klasnaam; command.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex); } finally { connection.Close(); } } }
public Klas GeefKlas(int id) { DbConnection connection = getConnection(); string query = "SELECT * FROM dbo.klas WHERE id=@id"; using (DbCommand command = connection.CreateCommand()) { command.CommandText = query; DbParameter paramId = sqlFactory.CreateParameter(); paramId.ParameterName = "@Id"; paramId.DbType = DbType.Int32; paramId.Value = id; command.Parameters.Add(paramId); connection.Open(); try { DbDataReader reader = command.ExecuteReader(); 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(); } } }
public Student GeefStudent(int id) { DbConnection connection = getConnection(); string queryS = "SELECT * FROM dbo.student WHERE id=@id"; string querySC = "SELECT * FROM [adresBeheer].[dbo].[cursus] t1,[adresBeheer].[dbo].[student_cursus] t2 " + "where t1.Id = t2.cursusid and t2.studentid = @id"; using (DbCommand command = connection.CreateCommand()) { command.CommandText = queryS; DbParameter paramId = sqlFactory.CreateParameter(); paramId.ParameterName = "@Id"; paramId.DbType = DbType.Int32; paramId.Value = id; command.Parameters.Add(paramId); connection.Open(); try { DbDataReader 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(); } } }
public Student(string naam, Klas klas) { this.naam = naam; this.klas = klas; this.cursussen = new List <Cursus>(); }