public ActionResult AddStudent(studentmodel MB,FormCollection formCollection) // Calling on http post (on Submit)
{
MB.classlistid = formCollection["classlistvalue"];
if (ModelState.IsValid)
{
DataLayer.student objDB = new DataLayer.student(); //calling class Dbdata
string result = objDB.AddStudent(MB); // passing Value to DBClass from model
ViewData["result"] = result; // for dislaying message after saving storing output.
ModelState.Clear(); //clearing model
return View();
}
else
{
ModelState.AddModelError("", "Error in saving data");
return View();
}
}
con = new SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ToString());
SqlCommand cmd = new SqlCommand("AddStudent", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@studentname", MD.studentname);
cmd.Parameters.AddWithValue("@gdname", MD.guardianname);
cmd.Parameters.AddWithValue("@gender", MD.gender);
cmd.Parameters.AddWithValue("@religion", MD.religion);
cmd.Parameters.AddWithValue("@email", MD.email);
cmd.Parameters.AddWithValue("@phone", MD.phone);
cmd.Parameters.AddWithValue("@studaderess", MD.address);
cmd.Parameters.AddWithValue("@class", MD.classlistid);
cmd.Parameters.AddWithValue("@section", MD.section);
cmd.Parameters.AddWithValue("@rollno", MD.rollno);
cmd.Parameters.AddWithValue("@studpic", "~/uploadpic/" + pic1);
cmd.Parameters.AddWithValue("@username", MD.username);
cmd.Parameters.AddWithValue("@pwd", MD.password);
cmd.Parameters.AddWithValue("@fname", MD.fname);
cmd.Parameters.AddWithValue("@mname", MD.mname);
cmd.Parameters.AddWithValue("@fprofession", MD.fprofession);
cmd.Parameters.AddWithValue("@mprofession", MD.mprofession);
cmd.Parameters.AddWithValue("@pemail", MD.pemail);
cmd.Parameters.AddWithValue("@mob1", MD.pphone1);
cmd.Parameters.AddWithValue("@mob2", MD.pphone2);
cmd.Parameters.AddWithValue("@permaddress", MD.paddress);
cmd.Parameters.AddWithValue("@lastschool", MD.lastschool);
cmd.Parameters.AddWithValue("@highesteducation", MD.lastclass);
cmd.Parameters.AddWithValue("@percentage", MD.percent);
con.Open();
result = cmd.ExecuteScalar().ToString();
return result;