public static void UpdateBand(int id) { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"UPDATE FROM bands WHERE band_id = @id;"; MySqlParameter bandId = new MySqlParameter(); bandId.ParameterName = "@id"; bandId.Value = id; cmd.Parameters.Add(bandId); cmd.ExecuteNonQuary(); conn.CLose(); if (conn != null) { conn.Dispose(); } }
public void AddVenue(Venue newVenue) { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"INSERT INTO venues_bands (venue_id, band_id) VALUES (@venueId, @bandId);"; MySqlParameter venue_id = new MySqlParameter(); venue_id.ParameterName = "@venueId"; venue_id.Value = newVenue.GetId(); cmd.Parameters.Add(band_id); cmd.ExecuteNonQuary(); conn.CLose(); if (conn != null) { conn.Dispose(); } }
public list <Venue> GetVenues() { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT venue_id FROM venues_bands WHERE band_id = @bandId;"; MySqlParameter venue_id = new MySqlParameter(); bandId.ParameterName = "@bandId"; bandId.Value = _id; cmd.Parameters.Add(bandId); var rdr = cmd.ExecuteReader() as MySqlDataReader; List <int> venueIds = new List <int> { }; while (rdr.Read()) { int venueId = rdr.GetInt32(0); string name = rdr.GetString(1); Venue newVenue = new Venue(name, id); venueIds.Add(venueId); } rdr.Dispose(); List <Venue> venues = new List <Venue> { }; foreach (int venueId in venueIds) { var venueQuery = conn.CreateCommand() as MySqlCommand; venueQuery.CommandText = @"SELECT * FROM venues WHERE id = @venueId;"; MySqlParameter venueIdParameter = new MySqlParameter(); venueIdParameter.ParameterName = "@venueId"; venueIdParameter.Value = venueId; venueQuery.Parameters.Add(venueIdParameter); var venueQueryRdr = venueQuery.ExecuteReader() as MySqlDataReader; while (venueQueryRdr.Read()) { int thisvenueId = venueQueryRdr.GetInt32(0); string venueName = venueQueryRdr.GetString(1); Venue foundVenue = new Venue(thisvenueId, venueName); venues.Add(foundVenue); } venueQueryRdr.Dispose(); } conn.CLose(); if (conn != null) { conn.Dispose(); } return(venues); }