Help Needed

Help Needed

  • NA
  • 13
  • 6k

MVC Delete Action Method

Aug 20 2016 3:56 PM
Hi All
 
  Here I am giving my simple stored procedure and Delete Action Method. When I am trying to delete the button it doesn't work.StoredProcedure Is working fine.But when I click delete button it won't delete the record from the table
 
Create procedure spDeleteEmployee
@Id int
as
Begin
Delete from Employee11 where Id = @Id
End
 
public void DeleteEmployee(int id)
{
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("spDeleteEmployee", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter paramId = new SqlParameter();
paramId.ParameterName = "@Id";
paramId.Value = id;
cmd.Parameters.Add(paramId);
con.Open();
cmd.ExecuteNonQuery();
}
}
 
 
 
[HttpPost]
public ActionResult DeleteEmployee(int id)
{
EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
employeeBusinessLayer.DeleteEmployee(id);
return RedirectToAction("Index");


Answers (2)