Submitting changes to 2 tables with C# linq only one table is changing
Posted
by Laurence Burke
on Stack Overflow
See other posts from Stack Overflow
or by Laurence Burke
Published on 2010-03-12T17:04:13Z
Indexed on
2010/03/12
17:07 UTC
Read the original article
Hit count: 316
SO I am changing the values in 2 different tables and the only table changing is the address table any one know why?
protected void btnSubmit_Click(object sender, EventArgs e)
{
TestDataClassDataContext dc = new TestDataClassDataContext();
var addr = (from a in dc.Addresses
where a.AddressID == Convert.ToInt32(ddlAddList.SelectedValue)
select a).FirstOrDefault();
var caddr = (from ca in dc.CustomerAddresses
where addr.AddressID == ca.AddressID
select ca).FirstOrDefault();
if (txtZip.Text != "" && txtAdd1.Text != "" && txtCity.Text != "")
{
addr.AddressLine1 = txtAdd1.Text;
addr.AddressLine2 = txtAdd2.Text;
addr.City = txtCity.Text;
addr.PostalCode = txtZip.Text;
addr.StateProvinceID = Convert.ToInt32(ddlState.SelectedValue);
caddr.AddressTypeID = Convert.ToInt32(ddlAddrType.SelectedValue);
dc.SubmitChanges();
lblErrMsg.Visible = false;
lblSuccess.Visible = true;
}
else
{
lblErrMsg.Text = "Invalid Input";
lblErrMsg.Visible = true;
}
}
© Stack Overflow or respective owner