Hello I am updating a few different tables with the same data from my main table, but after inserting say 4 or 5 records I get the above error for one of the tables, here is my code.
public static void InsertSnookerMainTable(string FirstName, string LastName, string Team)
{
try
{
using (var DB = new FinalWringtonValeDB())
{
BilliardBreaks SnookerMainTable = new BilliardBreaks();
SnookerMainTable.FirstName = FirstName;
SnookerMainTable.LastName = LastName;
Div1Breaks Div1Breaks = new Div1Breaks();
Div1Breaks.FirstName = FirstName;
Div1Breaks.LastName = LastName;
Div2Breaks Div2Breaks = new Div2Breaks();
Div2Breaks.FirstName = FirstName;
Div2Breaks.LastName = LastName;
Contacts Contact = new Contacts();
Contact.FirstName = FirstName;
Contact.LastName = LastName;
DB.SnookerHandicaps.Add(SnookerMainTable);
DB.Div1Breaks.Add(Div1Breaks);
DB.Div2Breaks.Add(Div2Breaks);
DB.Contacts.Add(Contact);
DB.SaveChanges();
}
}
catch (Exception ex)
{
Error:- ** Violation of PRIMARY KEY constraint . Cannot insert duplicate key **
return;
}
}