Hi All
Here I am giving my simple stored procedure and Delete Action Method. 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 Employee where Id = @Id
End
@Id int
as
Begin
Delete from Employee where Id = @Id
End
public void DeleteEmployee(int id)
{
string CS = ConfigurationManager.ConnectionStrings["Con"].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);
{
string CS = ConfigurationManager.ConnectionStrings["Con"].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();
}
cmd.ExecuteNonQuery();
}
}
[HttpPost]
public ActionResult DeleteEmployee(int id)
{
EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
employeeBusinessLayer.DeleteEmployee(id);
return RedirectToAction("Index");
}
public ActionResult DeleteEmployee(int id)
{
EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
employeeBusinessLayer.DeleteEmployee(id);
return RedirectToAction("Index");
}