DataClasses1DataContext dbcontext = new DataClasses1DataContext();
//insert
protected void Button1_Click(object sender, EventArgs e)
{
dbcontext = new DataClasses1DataContext();
PRDErrorCodes_ cd = new PRDErrorCodes_
{
ErrorCode = "test",
ErrorDescription = "testDesc"
};
dbcontext.PRDErrorCodes_s.InsertOnSubmit(cd);
dbcontext.SubmitChanges();
Response.Write("successfull inserted");
}
//update
protected void Button2_Click(object sender, EventArgs e)
{
var det = (from p in dbcontext.PRDErrorCodes_s
where p.ErrorCode.Equals("test")
select p).SingleOrDefault();
if (det != null)
{
det.ErrorCode = "new test";
det.ErrorDescription = "new test Desc";
dbcontext.SubmitChanges();
Response.Write("successfull saved");
}
}
//delete
protected void Button3_Click(object sender, EventArgs e)
{
PRDErrorCodes_ det = (from p in dbcontext.PRDErrorCodes_s
where p.ErrorCode.Equals("test")
select p).SingleOrDefault();
if (det != null)
{
dbcontext.PRDErrorCodes_s.DeleteOnSubmit(det);
dbcontext.SubmitChanges();
Response.Write("deleted saved");
}
}
//read
protected void Button4_Click(object sender, EventArgs e)
{
var det = (from p in dbcontext.PRDErrorCodes_s
select p).ToList();
GridView1.DataSource = det;
GridView1.DataBind();
}
No comments:
Post a Comment