Update data in two tables using MVC4

Posted by Mandlaa under ASP.NET MVC on 10/18/2013 | Points: 10 | Views : 1823 | Status : [Member] | Replies : 0
This is my code

[HttpPost]
public ActionResult Edit(string id,sample collection1,FormCollection collection)
{
TagTable p1 = db.TagTables.Single(s => s.TagId == id);
sample p = db.samples.Single(e => e.AccNo == id);
try
{
string[] Values = collection["AccNo"].ToString().Split(new Char[] { '.' });

int b = int.Parse(Values[0]);

int c = int.Parse(Values[1]);

string t = Values[2];
// TODO: Add update logic here

p.BatchId = collection1.BatchId=b;
p.ClientId = collection1.ClientId = c;
p.AccNo = collection1.AccNo = c + "." + b + "." + t;
db.SubmitChanges();

//Another table insert
TagTable td = new TagTable();

p1.BatchId = td.BatchId = b;
p1.ClientId = td.ClientId = c;
p1.TagId = td.TagId = c + "." + b + "." + t;
db.SubmitChanges();

return RedirectToAction("Index");
}
catch
{
return View();
}
}

I can update the data in two tables getting the following error

ERROR:

An exception of type 'System.InvalidOperationException' occurred in System.Data.Linq.dll but was not handled in user code

Additional information: Value of member 'TagId' of an object of type 'TagTable' changed.
My TagId datatype is Varchar




Responses

(No response found.)

Login to post response