public static int DeleteForignStudent(ForignStudent fs) { MySqlConnection connection = DBConnection.getDbConnection().getConnection(); try { connection.Open(); } catch { } try { MySqlCommand command; String newMemberSql = "DELETE FROM internationalstudent WHERE Name = '" + fs.Name + "' AND Country = '" + fs.Country + "' AND Coacher_member_athleticId = '" + fs.CoacherAtheleticId + "'"; command = connection.CreateCommand(); command.CommandText = newMemberSql; return(command.ExecuteNonQuery()); } catch (Exception ex) { throw ex; } finally { connection.Close(); } }
private void deleteInternationalStudentBtn_Click(object sender, EventArgs e) { int selectedrowindex = internationalStudentDataGridView.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = internationalStudentDataGridView.Rows[selectedrowindex]; ForignStudent fs = new ForignStudent(Convert.ToString(selectedRow.Cells[0].Value), Convert.ToString(selectedRow.Cells[1].Value), Convert.ToString(selectedRow.Cells[2].Value), member.AthleticId); try { CoacherController.DeleteForignStudent(fs); internationalStudentDataGridView.DataSource = CoacherController.GetForignStudents(member.AthleticId, StudentSelectType.Under_Coacher); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void addStudentBtn_Click(object sender, EventArgs e) { try { ForignStudent fs = new ForignStudent(nameText.Text, countryCombo.SelectedItem.ToString(), beltText.Text, id); CoacherController.AddForignStudent(fs); MessageBox.Show("Data added success!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); c.LoadData(); nameText.Clear(); beltText.Clear(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static int AddForignStudent(ForignStudent fs) { MySqlConnection connection = DBConnection.getDbConnection().getConnection();; try { connection.Open(); } catch (Exception ex) { } try { MySqlCommand command; String newMemberSql = "INSERT INTO internationalstudent (Name,Country,Belt,Coacher_member_athleticId) VALUES (@Name,@Country,@Belt,@Coacher_member_atheleticId)"; command = connection.CreateCommand(); command.CommandText = newMemberSql; command.Parameters.AddWithValue("@Name", fs.Name); command.Parameters.AddWithValue("@Country", fs.Country); command.Parameters.AddWithValue("@Belt", fs.Belt); command.Parameters.AddWithValue("@Coacher_member_atheleticId", fs.CoacherAtheleticId); return(command.ExecuteNonQuery()); } catch (Exception ex) { throw ex; } finally { connection.Close(); } }