예제 #1
0
 public void T4_Find_inDataBase()
 {
     Course firstCourse = new Course("Biology", 101);
       firstCourse.Save();
       Course resultCourse = Course.Find(firstCourse.GetId());
       Assert.Equal(firstCourse,resultCourse);
 }
예제 #2
0
        public void AddCourses(Course newCourse)
        {
            SqlConnection conn = DB.Connection();
            conn.Open();

            SqlCommand cmd = new SqlCommand("INSERT INTO students_courses (student_id, course_id) VALUES (@StudentId,@CourseId)",conn);

            SqlParameter studentIdParameter = new SqlParameter();
            studentIdParameter.ParameterName= "@StudentId";
            studentIdParameter.Value= this.GetId();

            SqlParameter courseIdParameter = new SqlParameter();
            courseIdParameter.ParameterName= "@CourseId";
            courseIdParameter.Value= newCourse.GetId();

            cmd.Parameters.Add(studentIdParameter);
            cmd.Parameters.Add(courseIdParameter);

            cmd.ExecuteNonQuery();

            if(conn != null)
            {
              conn.Close();
            }
        }