Procedure or function 'sp_InsertRecord_tblEmployee' expects parameter '@Name', which was not supplied.
getting the above mentioned error when executing the code why? can any one answer please.
here is the source code
BusinessLayer:
public List<employee> AddEmployee()
{
List<employee> employee = new List<employee>();
Employee objemp = new Employee();
try
{
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("sp_InsertRecord_tblEmployee", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", objemp.Name);
cmd.Parameters.AddWithValue("@Gender", objemp.Gender);
cmd.Parameters.AddWithValue("@City", objemp.City);
cmd.Parameters.AddWithValue("@DateofJoining", objemp.Dateofjoining.ToShortTimeString());
con.Open();
cmd.ExecuteNonQuery();
employee.Add(objemp);
}
return employee;
}
catch(Exception ex)
{
throw;
}
}
Entity Is
public class Employee
{
public string Name { set; get; }
public string Gender { set; get; }
public string City { set; get; }
public DateTime Dateofjoining { set; get; }
}
Code in Controllers is
Employee employee = new Employee();
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(FormCollection form)
{
BusinessLogic logic = new BusinessLogic();
employee.Name = form["Name"];
employee.Gender = form["Gender"];
employee.City = form["City"];
employee.Dateofjoining = Convert.ToDateTime(form["Dateofjoining"]);
logic.AddEmployee();
return View(form);
}
}