Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > ASP.NET 4.5 General Discussion
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 4.5 General Discussion For ASP.NET 4.5 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4.5 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 14th, 2017, 05:49 AM
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 66%
Activity: 66% Activity: 66% Activity: 66%
 
Join Date: Nov 2017
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Entity Framework Error : Violation of PRIMARY KEY constraint . Cannot insert duplicat

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;
}
}


I didn't find the right solution from the internet.
References:

brand videos
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 6: Unique Key Constraint Violation deebazz BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 0 July 10th, 2009 09:17 AM
Violation of PRIMARY KEY constraint??? twyce C# 1 September 9th, 2008 02:23 AM
Violation of primary key dhoward VB.NET 2002/2003 Basics 4 May 31st, 2007 11:19 AM
Primary Key Violation error code hasanali00 BOOK: ASP.NET Website Programming Problem-Design-Solution 1 April 19th, 2005 08:41 PM
primary key violation muralikeane Classic ASP Databases 8 May 21st, 2004 10:24 PM



All times are GMT -4. The time now is 10:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.