LINQ - Edit & Update with LINQ in asp.net with C#

Asked By vivek my on 28-Apr-14 04:06 PM
Hello Friends


1.i am working with Linq to Sql.in this i want update so first of all i created one table 
like 1.id-primary key-auto generated 2.name varchar(60) 3.phone varchar(60).


2.now i add one update page with name & phone & one button for update then.


3.now in update.cs page i coded this--

public partial class UpdateContacts : System.Web.UI.Page
    {
        DataClasses1DataContext Db = new DataClasses1DataContext();

protected void Page_Load(object sender, EventArgs e)
        {
            name = TextBox1.Text;
            phone = TextBox2.Text;
            if (Request.QueryString["id"] != null)
            {
                var qry = from m in Db.tblcontacts1s
                          where m.id == int.Parse(Request.QueryString["id"])
                          select m;
                foreach (var q in qry)
                {
                    TextBox1.Text = q.name;
                    TextBox2.Text = q.phone;
                 
            }
        }

        protected void UpdateBTN_Click(object sender, EventArgs e)
        {
            Session["name"] = name;
            Session["phone"] = phone;
            Response.Redirect("ConfirmUpdate.aspx?id={0}"+Request.QueryString["id"].ToString());
        }

4.then i add Confirmation page .

5.but unfortunately i could not updated & got one error like even i couldn't perform any up dation of my previous record.

Object reference not set to an instance of an object

6. please solve my query immediately....