I'm trying to make a method in my Admin class (for a small course project) which should INSERT
a new movie into my database.
I don't get any errors, but the new data is not inserted into the database. Here is my code:
public void AddMovieToDB(int mCodeLable, string title, int yearOfMovie, int lengthInMinutes, string dvdOrVhs, string genreOfMovie)
{
int movieCodeLable = mCodeLable;
string movieTitle = title;
int year = yearOfMovie;
int length = lengthInMinutes;
string typeOf = dvdOrVhs;
string genre = genreOfMovie;
string connectionString = @"Data Source=|DataDirectory|\VideoStoreDB.sdf";
SqlCeConnection connection = new SqlCeConnection(connectionString);
connection.Open();
SqlCeCommand command = new SqlCeCommand(
"INSERT INTO Movie(MovieCodeLable, Title, Year,
LengthMinutes, TypeOf, Genre)
VALUES(@mcl, @title, @year, @length, @typeOf, @genre)", connection);
command.Parameters.AddWithValue("@mcl", movieCodeLable);
command.Parameters.AddWithValue("@title", movieTitle);
command.Parameters.AddWithValue("@year", year);
command.Parameters.AddWithValue("@length", length);
command.Parameters.AddWithValue("@typeOf", typeOf);
command.Parameters.AddWithValue("@genre", genre);
command.ExecuteNonQuery();
connection.Close();
Console.WriteLine("Movie added to the DB!");
}
And this is how i call it from the Main:
Admin admin1 = new Admin();
admin1.AddMovieToDB(0151, "Play ball!", 2012, 124, "DVD", "Drama");