Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 4729

MVC

$
0
0
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
 
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);
con.Open();
cmd.ExecuteNonQuery();
}
}
 
 
 
[HttpPost]
public ActionResult DeleteEmployee(int id)
{
EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
employeeBusinessLayer.DeleteEmployee(id);
return RedirectToAction("Index");





Viewing all articles
Browse latest Browse all 4729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>