}//End of Load public List <SchoolYear> GetById() { try { //prepare connection string using (MySqlConnection con = new MySqlConnection(GOCSystem2018.Config.GetConnectionString())) { //try to open connection con.Open(); //prepare sql query string sql = "SELECT * FROM school_year WHERE id =@id;"; MySqlCommand cmd = new MySqlCommand(sql, con); cmd.Parameters.AddWithValue("id", id); MySqlDataReader reader = cmd.ExecuteReader(); //loop while have record while (reader.Read()) { //instantiate model SchoolYear schoolYear = new SchoolYear(); //prepare properties schoolYear.id = Convert.ToInt32(reader["id"].ToString()); schoolYear.yearStart = reader["year_start"].ToString(); schoolYear.yearEnd = reader["year_end"].ToString(); schoolYear.semester = reader["semster"].ToString(); schoolYear.quaterGrading = reader["quarter_grading"].ToString(); schoolYears.Add(schoolYear); } } } catch (MySqlException ex) { MessageBox.Show("ERROR : " + ex.ToString(), "GOCINFOSYS", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(schoolYears); }
//Functions----------------------------------------------------------------------------------------------------------------------------// public void LoadSchoolYear() { SchoolYear schoolYear = new SchoolYear(); List <SchoolYear> schoolYears = new List <SchoolYear>(); //clear list schoolYears.Clear(); //pass value to list schoolYears = schoolYear.Load(); //loop through load it to list view foreach (var item in schoolYears) { //Load to datagridView //dgvDiscount.Rows.Add(item.Id, item.DiscountName, item.DiscountAmount); //string School; //School = (item.YearStart + " - " + item.YearEnd); //lblSY.Text = School; lblSemester.Text = item.Semester; //lblQGrading.Text = item.Quarter; //cmbSchoolYear.Items.Add(School); } }//End LoadRecords()