Example #1
0
        public Cursus GeefCursus(int id)
        {
            DbConnection connection = getConnection();
            string       query      = "SELECT * FROM dbo.cursus 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();
                    Cursus cursus = new Cursus((int)reader["Id"], (string)reader["cursusnaam"]);
                    reader.Close();
                    return(cursus);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return(null);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Example #2
0
        public void VoegCursusToe(Cursus c)
        {
            DbConnection connection = getConnection();
            string       query      = "INSERT INTO dbo.cursus (cursusnaam) VALUES(@cursusnaam)";

            using (DbCommand command = connection.CreateCommand())
            {
                connection.Open();
                try
                {
                    DbParameter parNaam = sqlFactory.CreateParameter();
                    parNaam.ParameterName = "@cursusnaam";
                    parNaam.DbType        = DbType.String;
                    command.Parameters.Add(parNaam);
                    command.CommandText = query;
                    command.Parameters["@cursusnaam"].Value = c.cursusnaam;
                    command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Example #3
0
        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();
                }
            }
        }
Example #4
0
        public void UpdateCursus(Cursus c)
        {
            DbConnection connection = getConnection();
            Cursus       cursusDB   = GeefCursus(c.id);
            string       query      = "SELECT * FROM dbo.cursus WHERE Id=@Id";

            using (DbDataAdapter adapter = sqlFactory.CreateDataAdapter())
            {
                try
                {
                    DbParameter paramId = sqlFactory.CreateParameter();
                    paramId.ParameterName = "@Id";
                    paramId.DbType        = DbType.Int32;
                    paramId.Value         = c.id;
                    DbCommandBuilder builder = sqlFactory.CreateCommandBuilder();
                    builder.DataAdapter               = adapter;
                    adapter.SelectCommand             = sqlFactory.CreateCommand();
                    adapter.SelectCommand.CommandText = query;
                    adapter.SelectCommand.Connection  = connection;
                    adapter.SelectCommand.Parameters.Add(paramId);
                    adapter.UpdateCommand = builder.GetUpdateCommand();
                    DataTable table = new DataTable();
                    adapter.Fill(table);
                    table.Rows[0]["cursusnaam"] = c.cursusnaam;

                    adapter.Update(table);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Example #5
0
 public void voegCursusToe(Cursus c)
 {
     cursussen.Add(c);
 }