using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Entity;
using System.Data.SqlClient;
namespace DemoEntityFrameWork
{
public partial class Default2 : System.Web.UI.Page
{
DBPABITRAEntities dbcontext = new DBPABITRAEntities();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
TBL_EMP_ENTITY ob = new TBL_EMP_ENTITY();
try
{
ob.EM_ID = int.Parse(TextBox1.Text);
ob.EM_NAME = TextBox2.Text;
ob.EM_STATUS = "1";
dbcontext.TBL_EMP_ENTITY.Add(ob);
dbcontext.SaveChanges();
TextBox1.Text = "";
TextBox2.Text = "";
Response.Write("<script>alert('Save Sucessfully !');</script>");
}catch(SqlException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
DBPABITRAEntities db = new DBPABITRAEntities();
int ID=Convert.ToInt32(TextBox1.Text);
var empQuery = from emp in db.TBL_EMP_ENTITY
where emp.EM_ID == ID
select emp;
TBL_EMP_ENTITY ob = empQuery.Single();
ob.EM_ID = int.Parse(TextBox1.Text);
ob.EM_NAME = TextBox2.Text;
ob.EM_STATUS = "1";
int x= db.SaveChanges();
Response.Write(x.ToString()+"Record Will be Updated......");
}
protected void btnDelete_Click(object sender, EventArgs e)
{
DBPABITRAEntities db = new DBPABITRAEntities();
int ID = Convert.ToInt32(TextBox1.Text);
//create a new object using the value of EmpId
TBL_EMP_ENTITY objEmp = new TBL_EMP_ENTITY() { EM_ID = ID };
//attach and delete object
db.TBL_EMP_ENTITY.Attach(objEmp);
//db.TBL_EMP_ENTITYS.DeleteObject(objEmp);
//save changes
db.SaveChanges();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Entity;
using System.Data.SqlClient;
namespace DemoEntityFrameWork
{
public partial class Default2 : System.Web.UI.Page
{
DBPABITRAEntities dbcontext = new DBPABITRAEntities();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
TBL_EMP_ENTITY ob = new TBL_EMP_ENTITY();
try
{
ob.EM_ID = int.Parse(TextBox1.Text);
ob.EM_NAME = TextBox2.Text;
ob.EM_STATUS = "1";
dbcontext.TBL_EMP_ENTITY.Add(ob);
dbcontext.SaveChanges();
TextBox1.Text = "";
TextBox2.Text = "";
Response.Write("<script>alert('Save Sucessfully !');</script>");
}catch(SqlException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
DBPABITRAEntities db = new DBPABITRAEntities();
int ID=Convert.ToInt32(TextBox1.Text);
var empQuery = from emp in db.TBL_EMP_ENTITY
where emp.EM_ID == ID
select emp;
TBL_EMP_ENTITY ob = empQuery.Single();
ob.EM_ID = int.Parse(TextBox1.Text);
ob.EM_NAME = TextBox2.Text;
ob.EM_STATUS = "1";
int x= db.SaveChanges();
Response.Write(x.ToString()+"Record Will be Updated......");
}
protected void btnDelete_Click(object sender, EventArgs e)
{
DBPABITRAEntities db = new DBPABITRAEntities();
int ID = Convert.ToInt32(TextBox1.Text);
//create a new object using the value of EmpId
TBL_EMP_ENTITY objEmp = new TBL_EMP_ENTITY() { EM_ID = ID };
//attach and delete object
db.TBL_EMP_ENTITY.Attach(objEmp);
//db.TBL_EMP_ENTITYS.DeleteObject(objEmp);
//save changes
db.SaveChanges();
}
}
}
No comments:
Post a Comment