Hello
I am inserting new data in 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())
{
Table1 SnookerMainTable = new Table1();
SnookerMainTable.FirstName = FirstName;
SnookerMainTable.LastName = LastName;
Table2 Div1Breaks = new Table2();
Div1Breaks.FirstName = FirstName;
Div1Breaks.LastName = LastName;
Table3 Div2Breaks = new Table3();
Div2Breaks.FirstName = FirstName;
Div2Breaks.LastName = LastName;
Table4 Contact = new Table4();
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;
}
}