How to Add Records using Ms-Access Database in MVC4 With Pure Ms-Access
There are two types of methods HttpPost and HttpGet Post method is used to save the record by inserting the values. Get method is used to show the entry form design
[HttpPost]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(FormCollection frm1)
{
Employee emp = new Employee();
emp.EmpId = Convert.ToInt32(frm1["EmpId"]);
emp.EmpName = frm1["EmpName"];
emp.EmpNo = frm1["EmpNo"];
string mycon = @"PROVIDER=Microsoft.JET.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("\\Temp.mdb");
OleDbConnection con = new OleDbConnection(mycon);
con.Open();
OleDbCommand command = new OleDbCommand("Insert into Table1 values(@EmpId,@EmpNo,@EmpName)", con);
command.CommandType = CommandType.Text;
command.Parameters.Add("@EmpId", emp.EmpId);
command.Parameters.Add("@Empno", emp.EmpNo);
command.Parameters.Add("@EmpName",emp.EmpName);
int rows = command.ExecuteNonQuery();
return View();
}
[HttpPost]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(FormCollection frm1)
{
Employee emp = new Employee();
emp.EmpId = Convert.ToInt32(frm1["EmpId"]);
emp.EmpName = frm1["EmpName"];
emp.EmpNo = frm1["EmpNo"];
string mycon = @"PROVIDER=Microsoft.JET.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("\\Temp.mdb");
OleDbConnection con = new OleDbConnection(mycon);
con.Open();
OleDbCommand command = new OleDbCommand("Insert into Table1 values(@EmpId,@EmpNo,@EmpName)", con);
command.CommandType = CommandType.Text;
command.Parameters.Add("@EmpId", emp.EmpId);
command.Parameters.Add("@Empno", emp.EmpNo);
command.Parameters.Add("@EmpName",emp.EmpName);
int rows = command.ExecuteNonQuery();
return View();
}
No comments:
Post a Comment