예제 #1
0
        public void Save()
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("INSERT INTO bands (name) OUTPUT INSERTED.id VALUES (@Name);", conn);

            cmd.Parameters.Add(new SqlParameter("@Name", this.GetName()));

            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                this._id = rdr.GetInt32(0);
            }

            DB.CloseSqlConnection(rdr, conn);
        }
예제 #2
0
        public void UpdateName(string newName)
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("UPDATE venues SET name = @NewName OUTPUT INSERTED.name WHERE id=@VenueId;", conn);

            cmd.Parameters.Add(new SqlParameter("@NewName", newName));
            cmd.Parameters.Add(new SqlParameter("@VenueId", this.GetId()));

            SqlDataReader rdr = cmd.ExecuteReader();

//can't i just set _name = newName ?
            while (rdr.Read())
            {
                this._name = rdr.GetString(0);
            }

            DB.CloseSqlConnection(rdr, conn);
        }
예제 #3
0
        public static List <Band> GetAll()
        {
            List <Band> allBands = new List <Band> {
            };

            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand    cmd = new SqlCommand("SELECT * FROM bands", conn);
            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                int    bandId   = rdr.GetInt32(0);
                string bandName = rdr.GetString(1);
                Band   newBand  = new Band(bandName, bandId);
                allBands.Add(newBand);
            }

            DB.CloseSqlConnection(rdr, conn);

            return(allBands);
        }
예제 #4
0
        public static List <Venue> GetAll()
        {
            List <Venue> allVenues = new List <Venue> {
            };

            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand    cmd = new SqlCommand("SELECT * FROM venues", conn);
            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                int    venueId   = rdr.GetInt32(0);
                string venueName = rdr.GetString(1);
                Venue  newVenue  = new Venue(venueName, venueId);
                allVenues.Add(newVenue);
            }

            DB.CloseSqlConnection(rdr, conn);

            return(allVenues);
        }
예제 #5
0
        public void UpdateBand(Band OldBand, Band newBand)
        {
            int OldBandId = OldBand.GetId();

            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("UPDATE bands_venues SET band_id = @NewBandId WHERE band_id = @OldBandId AND venue_id = @VenueId;", conn);

            SqlParameter venueParameter   = new SqlParameter("@VenueId", this.GetId());
            SqlParameter oldBandParameter = new SqlParameter("@OldBandId", OldBandId);
            SqlParameter newBandParameter = new SqlParameter("@NewBandId", newBand.GetId());

            cmd.Parameters.Add(venueParameter);
            cmd.Parameters.Add(oldBandParameter);
            cmd.Parameters.Add(newBandParameter);

            SqlDataReader rdr = null;

            cmd.ExecuteNonQuery();

            DB.CloseSqlConnection(rdr, conn);
        }
예제 #6
0
        public void UpdateVenue(Venue OldVenue, Venue newVenue)
        {
            int OldVenueId = OldVenue.GetId();

            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("UPDATE bands_venues SET venue_id = @NewVenueId WHERE venue_id = @OldVenueId AND band_id = @BandId;", conn);

            SqlParameter bandParameter     = new SqlParameter("@BandId", this.GetId());
            SqlParameter oldVenueParameter = new SqlParameter("@OldVenueId", OldVenueId);
            SqlParameter newVenueParameter = new SqlParameter("@NewVenueId", newVenue.GetId());

            cmd.Parameters.Add(bandParameter);
            cmd.Parameters.Add(oldVenueParameter);
            cmd.Parameters.Add(newVenueParameter);

            SqlDataReader rdr = null;

            cmd.ExecuteNonQuery();

            DB.CloseSqlConnection(rdr, conn);
        }