private void delete(Lapin lapin) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("delete from Lapin where id=@id", cnx)) { cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32)); cmd.Parameters["@id"].Value = lapin.Id; cmd.ExecuteNonQuery(); } } }
private void insert(Course course) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("insert into Course(distance) values(@distance)", cnx)) { cmd.Parameters.Add(new MySqlParameter("@distance", MySqlDbType.Int32)); cmd.Parameters["@distance"].Value = course.Distance; cmd.ExecuteNonQuery(); // Todo gérer LastInsertId } } course.State = State.unChanged; }
private void update(Course course) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("update Course set distance=@distance where id=@id", cnx)) { cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@distance", MySqlDbType.Int32)); cmd.Parameters["@id"].Value = course.Id; cmd.Parameters["@distance"].Value = course.Distance; cmd.ExecuteNonQuery(); } } course.State = State.unChanged; }
public List <Lapin> GetAll(int idCourse) { List <Lapin> lapins = new List <Lapin>(); using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("select id,surnom,age,position,dossard from Lapin where idCourse=@idCourse", cnx)) { using (MySqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { lapins.Add(new Lapin(Convert.ToInt32(rdr["id"]), rdr["surnom"].ToString(), Convert.ToInt32(rdr["age"]), Convert.ToInt32(rdr["dossard"]), Convert.ToInt32(rdr["position"]), State.unChanged)); } } } } return(lapins); }
public Lapin GetById(int id) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("select id,surnom,age,position,dossard from Lapin where id=@id", cnx)) { cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32)); cmd.Parameters["@id"].Value = id; using (MySqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { return(new Lapin(Convert.ToInt32(rdr["id"]), rdr["surnom"].ToString(), Convert.ToInt32(rdr["age"]), Convert.ToInt32(rdr["dossard"]), Convert.ToInt32(rdr["position"]), State.unChanged)); } } } } throw new Exception("id non défini pour la table Lapin"); }
public Course GetById(int id) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("select id,distance from Course where id=@id", cnx)) { cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32)); cmd.Parameters["@id"].Value = id; using (MySqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { return(new Course(Convert.ToInt32(rdr["id"]), Convert.ToInt32(rdr["distance"]), State.unChanged)); } } } } throw new Exception("id non défini pour la table Course"); }
public List <Course> GetAll() { List <Course> courses = new List <Course>(); using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("select id,distance from Course", cnx)) { using (MySqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { courses.Add(new Course(Convert.ToInt32(rdr["id"]), Convert.ToInt32(rdr["distance"]), State.unChanged)); } } } } return(courses); }
private void update(Lapin lapin) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("update Lapin set surnom=@surnom,age=@age,position=@position,dossard=@dossard idCourse=@idCourse where id=@id", cnx)) { cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@age", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@position", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@dossard", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@surnom", MySqlDbType.VarChar)); cmd.Parameters["@id"].Value = lapin.Id; cmd.Parameters["@age"].Value = lapin.Age; cmd.Parameters["@position"].Value = lapin.GetPosition(); cmd.Parameters["@dossard"].Value = lapin.Dossard; cmd.Parameters["@surnom"].Value = lapin.GetSurnom(); cmd.ExecuteNonQuery(); } } lapin.State = State.unChanged; }
private void insert(Lapin lapin) { using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection()) { cnx.Open(); using (MySqlCommand cmd = new MySqlCommand("insert into Lapin(surnom,age,position,dossard,idCourse) values(@surnom,@age,@position,@dossard,@idCourse)", cnx)) { cmd.Parameters.Add(new MySqlParameter("@idCourse", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@age", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@position", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@dossard", MySqlDbType.Int32)); cmd.Parameters.Add(new MySqlParameter("@surnom", MySqlDbType.VarChar)); cmd.Parameters["@id"].Value = lapin.Id; cmd.Parameters["@age"].Value = lapin.Age; cmd.Parameters["@position"].Value = lapin.GetPosition(); cmd.Parameters["@dossard"].Value = lapin.Dossard; cmd.Parameters["@surnom"].Value = lapin.Surnom; cmd.ExecuteNonQuery(); // Todo coder la récupération de LastId } } lapin.State = State.unChanged; }