21 February 2014

Update Query in Linq



LINQ Update Query:

MydbDataContext db = new MydbDataContext();
        tbl_student stu = db.tbl_students.Single(x=>x.Id==102);
        stu.Name = "Jc.Pavan";
        db.SubmitChanges();

Before Table data

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 Update : 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==102);
        stu.Name = "Jc.Pavan";
        db.SubmitChanges();

    }
}


After Table data (Output):

No comments:

Post a Comment