Submitting changes to 2 tables with C# linq only one table is changing
- by Laurence Burke
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;
}
}