public bool Delete(Movie movie) { try { bool result = false; string DeleteProcedure = "[dbo].nameOfTheProcedure"; using (SqlConnection conn = DB.GetSqlConnection()) { using (SqlCommand cmd = new SqlCommand(DeleteProcedure, conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@MovieId", SqlDbType.NVarChar).Value = movie.Id; cmd.Parameters.Add("@Title", SqlDbType.NVarChar).Value = movie.Title; cmd.Parameters.Add("@Director", SqlDbType.NVarChar).Value = movie.Director; conn.Open(); result = cmd.ExecuteNonQuery() == 1; } } return result; } catch (SqlException ex) { Console.WriteLine(ex.Message); return false; } }
CREATE PROCEDURE [dbo].[nameOfTheProcedure] @MOVIEID NVARCHAR(10), @TITLE NVARCHAR(MAX) -- This should be irrelevent - the ID should be unique. AS DELETE FROM [dbo].[YourDBTableName] WHERE Id = @MOVIEID GO
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)