//Zad 4.3 public Cw4 GetStudentBySemester(string indexNumber) { using (SqlConnection con = new SqlConnection(ConString)) using (SqlCommand com = new SqlCommand()) { com.Connection = con; com.CommandText = "select Student.FirstName, Student.LastName, Student.BirthDate, Studies.Name, Enrollment.Semester from Student join Enrollment on Student.IdEnrollment = Enrollment.IdEnrollment join Studies on Enrollment.IdStudy = Studies.IdStudy where indexNumber=@index"; SqlParameter par = new SqlParameter(); par.Value = indexNumber; par.ParameterName = "index"; com.Parameters.Add(par); con.Open(); SqlDataReader dr = com.ExecuteReader(); while (dr.Read()) { var zad = new Cw4(); zad.FirstName = dr["FirstName"].ToString(); zad.LastName = dr["LastName"].ToString(); zad.BirthDate = dr["BirthDate"].ToString(); zad.Name = dr["Name"].ToString(); zad.Semester = dr.GetInt32(4); return(zad); } } return(null); }
//ZAD. 4.2 public IEnumerable <Cw4> GetStudentsByEnrollment() { var list = new List <Cw4>(); using (SqlConnection con = new SqlConnection(ConString)) using (SqlCommand com = new SqlCommand()) { com.Connection = con; com.CommandText = "select Student.FirstName, Student.LastName, Student.BirthDate, Studies.Name, Enrollment.Semester from Student join Enrollment on Student.IdEnrollment = Enrollment.IdEnrollment join Studies on Enrollment.IdStudy = Studies.IdStudy"; con.Open(); SqlDataReader dr = com.ExecuteReader(); while (dr.Read()) { var zad = new Cw4(); zad.FirstName = dr["FirstName"].ToString(); zad.LastName = dr["LastName"].ToString(); zad.BirthDate = dr["BirthDate"].ToString(); zad.Name = dr["Name"].ToString(); zad.Semester = dr.GetInt32(4); list.Add(zad); } } return(list); }