Click here to Skip to main content
15,887,416 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: fpassing asp.net field Pin
Not Active2-Nov-11 2:17
mentorNot Active2-Nov-11 2:17 
Questiontable control asp.net 2010 Pin
classy_dog1-Nov-11 9:27
classy_dog1-Nov-11 9:27 
AnswerRe: table control asp.net 2010 Pin
Dennis E White1-Nov-11 12:01
professionalDennis E White1-Nov-11 12:01 
QuestionAsync Report MVC3 Pin
eddieangel1-Nov-11 7:00
eddieangel1-Nov-11 7:00 
QuestionNeeded Code of changing dropdownlist Pin
Raghu1630-Oct-11 19:28
Raghu1630-Oct-11 19:28 
AnswerRe: Needed Code of changing dropdownlist Pin
Anurag Gandhi30-Oct-11 22:47
professionalAnurag Gandhi30-Oct-11 22:47 
QuestionCan't see my site's flash in an iframe tag Pin
benams30-Oct-11 6:37
benams30-Oct-11 6:37 
QuestionSubmitChanges is not working Pin
classy_dog29-Oct-11 8:17
classy_dog29-Oct-11 8:17 
I am working on a C#.net 2010 application I just wrote. Right now I am getting the error

'Cannot add an entity that already exists'. I get that error on the following line of code: attPlanDataContext.SubmitChanges();

I am trying to write to a table that has one to many rows that relate to the main table. When I try to add the second row to the table, that is when the error occurs.

I am hoping you can suggest what I need to change to fix this error. The following is the code that is affected by this error:

[^] protected void submitbutton(object sender, EventArgs e)
{

if (!Page.IsPostBack)
return;

CustomerDataContext attDataContext = new CustomerDataContext();
Customer att = null;
att = new Customer();
InsertCustomer(att);
attDataContext.Customer.InsertOnSubmit(att);
attDataContext.SubmitChanges();
CustomerDataContext attPlanDataContext = new CustomerDataContext();
Plan attplan = null;
attplan = new Plan();
InsertPlans(attplan, att, attPlanDataContext);

}
protected void InsertCustomer(Customer att)
{
// fills in data here
}
protected void InsertPlans(Plan attplan,Customer att, CustomerDataContext attPlanDataContext)
{


for (int i = 0; i < ChkBoxLstPlan.Items.Count; i++)
{

if (ChkBoxLstPlan.Items[i].Selected)
{
attplan.Att_id = att.Att_id;
attplan.Number = ChkBoxLstPlan.Items[i].Value.Substring(0, 5);
// Update the database
attPlanDataContext.Plans.InsertOnSubmit(attplan);
attPlanDataContext.SubmitChanges();
}
}

}
[^]
AnswerRe: SubmitChanges is not working Pin
Richard MacCutchan29-Oct-11 22:38
mveRichard MacCutchan29-Oct-11 22:38 
GeneralRe: SubmitChanges is not working Pin
classy_dog30-Oct-11 11:06
classy_dog30-Oct-11 11:06 
GeneralRe: SubmitChanges is not working Pin
Richard MacCutchan30-Oct-11 23:36
mveRichard MacCutchan30-Oct-11 23:36 
AnswerRe: SubmitChanges is not working Pin
phil.o29-Oct-11 23:54
professionalphil.o29-Oct-11 23:54 
GeneralRe: SubmitChanges is not working Pin
classy_dog30-Oct-11 11:08
classy_dog30-Oct-11 11:08 
GeneralRe: SubmitChanges is not working Pin
phil.o30-Oct-11 23:18
professionalphil.o30-Oct-11 23:18 
AnswerRe: SubmitChanges is not working Pin
oujeboland30-Oct-11 7:03
oujeboland30-Oct-11 7:03 
GeneralRe: SubmitChanges is not working Pin
classy_dog30-Oct-11 11:09
classy_dog30-Oct-11 11:09 
Questionvalidation control final? Pin
classy_dog29-Oct-11 8:05
classy_dog29-Oct-11 8:05 
AnswerRe: validation control final? Pin
Brij1-Nov-11 1:34
mentorBrij1-Nov-11 1:34 
QuestionHow to implement an automatic task in asp.net Pin
TRAORE cheickna29-Oct-11 2:40
TRAORE cheickna29-Oct-11 2:40 
AnswerRe: How to implement an automatic task in asp.net Pin
Philippe Mori29-Oct-11 3:15
Philippe Mori29-Oct-11 3:15 
GeneralRe: How to implement an automatic task in asp.net Pin
TRAORE cheickna29-Oct-11 3:41
TRAORE cheickna29-Oct-11 3:41 
GeneralRe: How to implement an automatic task in asp.net Pin
Philippe Mori29-Oct-11 4:23
Philippe Mori29-Oct-11 4:23 
AnswerRe: How to implement an automatic task in asp.net Pin
Not Active29-Oct-11 4:23
mentorNot Active29-Oct-11 4:23 
Questionwebform error Pin
sc steinhayse28-Oct-11 11:42
sc steinhayse28-Oct-11 11:42 
Questioncustom validator Pin
Member 821751728-Oct-11 5:14
Member 821751728-Oct-11 5:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.