I am using this code to update table record using linq. Please tell me what to do as code is executing but no changes are being made to database. Code is as follows:
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
bool temp = false; ;
nsmainDataContext stc = new nsmainDataContext();
nodeinfo tbl = stc.nodeinfos.Where(m => m.nodeid == Convert.ToInt32(DropDownList1.SelectedValue)).SingleOrDefault();
if(RadioButtonList1.SelectedItem==null)
{
Label3.Visible = true;
Label3.Text = "Please select a valid choice";
}
else
{
if(RadioButtonList1.SelectedIndex==1)
{
temp = true;
tbl.nodetstatus = temp;
}
else
if(RadioButtonList1.SelectedIndex==2)
{
temp = false;
tbl.nodetstatus = temp;
}
tbl.statuschangelog = System.DateTime.Now.ToString();
//stc.SubmitChanges();
Label3.Visible = true;
Label3.Text = "Status of node " + DropDownList1.SelectedValue + " successfully changed";
}
}

Suraj SahooPosted Jan 13, 2015, 3:48 AM
In the query you have posted, your context i.e. stc would be having the context for each entities like the nodeinfoes for nodeinfo table.
So you need to use
stc.nodeinfoes.AddOrUpdate(tbl);//nodeinfoes or any table context entity you will be updating
stc.SaveChanges();
This will then search for the primary key in the tbl object and then update if already present else will add an object with these records.
I hope you got this.
Please post back your queries if any.
Thanks
Ananth Padmanabham vemulaPosted Jan 2, 2015, 5:39 AM
stc.SubmitChanges();
it will save the change to database.
Manish Kumar ChoudharyPosted Nov 18, 2014, 2:02 AM
it will save the change to database. without using this method whatever change you made will not reflect to database.
Ramesh MaruthiPosted Nov 17, 2014, 9:03 PM
after changing the values you need to save the changes of the context
try
{
stc.savechanges();
}
catch(Exception ex)
{
throw ex;
}