21 February 2014

LINQ Deleter Query in c#.net

LINQ Deleter Query:

MydbDataContext db = new MydbDataContext();
        tbl_student stu = db.tbl_students.Single(x => x.Id == 103);
        db.tbl_students.DeleteOnSubmit(stu);
        db.SubmitChanges();


C#.net Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Delete : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MydbDataContext db = new MydbDataContext();
        tbl_student stu = db.tbl_students.Single(x => x.Id == 103);
        db.tbl_students.DeleteOnSubmit(stu);
        db.SubmitChanges();

    }
}

No comments:

Post a Comment