public void AddStudent(Student stud) { StudentList.Add(stud); }
public Student GetStudentDetail(string id, ref List <string> errors) { var conn = new SqlConnection(ConnectionString); Student student = null; try { var adapter = new SqlDataAdapter(GetStudentInfoProcedure, conn) { SelectCommand = { CommandType = CommandType.StoredProcedure } }; adapter.SelectCommand.Parameters.Add(new SqlParameter("@student_id", SqlDbType.VarChar, 20)); adapter.SelectCommand.Parameters["@student_id"].Value = id; var dataSet = new DataSet(); adapter.Fill(dataSet); if (dataSet.Tables[0].Rows.Count == 0) { return(null); } student = new Student { StudentId = dataSet.Tables[0].Rows[0]["student_id"].ToString(), FirstName = dataSet.Tables[0].Rows[0]["first_name"].ToString(), LastName = dataSet.Tables[0].Rows[0]["last_name"].ToString(), SSN = dataSet.Tables[0].Rows[0]["ssn"].ToString(), Email = dataSet.Tables[0].Rows[0]["email"].ToString(), Password = dataSet.Tables[0].Rows[0]["password"].ToString(), ShoeSize = (float)Convert.ToDouble(dataSet.Tables[0].Rows[0]["shoe_size"].ToString()), Weight = Convert.ToInt32(dataSet.Tables[0].Rows[0]["weight"].ToString()) }; if (dataSet.Tables[1] != null) { student.Enrolled = new List <Schedule>(); for (var i = 0; i < dataSet.Tables[1].Rows.Count; i++) { var schedule = new Schedule(); var course = new Course { CourseId = dataSet.Tables[1].Rows[i]["course_id"].ToString(), Title = dataSet.Tables[1].Rows[i]["course_title"].ToString(), Description = dataSet.Tables[1].Rows[i]["course_description"].ToString() }; schedule.Course = course; schedule.Quarter = dataSet.Tables[1].Rows[i]["quarter"].ToString(); schedule.Year = dataSet.Tables[1].Rows[i]["year"].ToString(); schedule.Session = dataSet.Tables[1].Rows[i]["session"].ToString(); schedule.ScheduleId = Convert.ToInt32(dataSet.Tables[1].Rows[i]["schedule_id"].ToString()); student.Enrolled.Add(schedule); } } } catch (Exception e) { errors.Add("Error: " + e); } finally { conn.Dispose(); } return(student); }