Пример #1
0
        public List <Dvd> DvdByRating(string rating)
        {
            List <Dvd> dvds = new List <Dvd>();

            using (var cn = new SqlConnection(StringBridge.ConnectionString()))
            {
                SqlCommand command = new SqlCommand("DvdByRating", cn);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@RatingType", rating);

                cn.Open();

                using (SqlDataReader rd = command.ExecuteReader())
                {
                    while (rd.Read())
                    {
                        Dvd dvd = new Dvd();
                        dvd.DvdId       = (int)rd["Id"];
                        dvd.Title       = rd["Title"].ToString();
                        dvd.ReleaseYear = (int)rd["ReleaseYear"];
                        dvd.Director    = rd["DirectorName"].ToString();
                        dvd.Rating      = rd["RatingType"].ToString();
                        dvd.Notes       = rd["Notes"].ToString();

                        dvds.Add(dvd);
                    }
                }
                return(dvds);
            }
        }
Пример #2
0
 public void DeleteDvd(int id)
 {
     using (var cn = new SqlConnection(StringBridge.ConnectionString()))
     {
         SqlCommand command = new SqlCommand("DeleteDvd", cn);
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.AddWithValue("@Id", id);
         cn.Open();
         command.ExecuteNonQuery();
         cn.Close();
     }
 }
Пример #3
0
        public void EditDvd(Dvd dvd)
        {
            using (var cn = new SqlConnection(StringBridge.ConnectionString()))
            {
                SqlCommand command = new SqlCommand("EditDvd", cn);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("@ID", dvd.DvdId);
                command.Parameters.AddWithValue("@ReleaseYear", dvd.ReleaseYear);
                command.Parameters.AddWithValue("@DirectorName", dvd.Director);
                command.Parameters.AddWithValue("@RatingName", dvd.Rating);
                command.Parameters.AddWithValue("@Notes", dvd.Notes);
                cn.Open();
                command.ExecuteNonQuery();
                cn.Close();
            }
        }