Ejemplo n.º 1
0
        internal static void AddMovie(RentInfo newmovie)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["MovieRental"].ConnectionString;
            //string queryString0 = @"Delete from MOVIE_INFO where MOVIE_ID = @MOVIE_ID";
            string queryString = @"Insert into MOVIE_INFO (MOVIE_ID,MOVIE_TITLE)
                                    values(@MOVIE_ID,@MOVIE_TITLE)";

            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand cmd2 = new SqlCommand();

                try
                {
                    cmd2 = new SqlCommand(queryString, connection);

                    cmd2.Parameters.AddWithValue("@MOVIE_ID", newmovie.movieID);
                    cmd2.Parameters.AddWithValue("@MOVIE_TITLE", newmovie.movieTitle);

                    cmd2.ExecuteNonQuery();

                    MessageBox.Show("Movie " + newmovie.movieID + ": " + newmovie.movieTitle +
                                    " was successfully added.");
                    connection.Close();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                    connection.Close();
                }
            }
        }
        public void addMovie(int id, String movietitle)
        {
            RentInfo newmovie = new RentInfo()
            {
                movieID    = id,
                movieTitle = movietitle
            };

            if (id <= 0 || movietitle == "")
            {
                MessageBox.Show("ID and movie title are required");
            }
            else
            {
                RentalInfoModel.AddMovie(newmovie);
            }
        }