Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2007, 03:05 PM
Authorized User
 
Join Date: Oct 2006
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default primary key constraint

I am getting this particular error....

Violation of PRIMARY KEY constraint 'PK_tblTempOnlineFWApplicant'. Cannot insert duplicate key in object 'tblTempOnlineFWApplicant'. Violation of PRIMARY KEY constraint 'PK_tblTempOnlineFWCompany'. Cannot insert duplicate key in object 'tblTempOnlineFWCompany'. Violation of PRIMARY KEY constraint 'PK_tblTempOnlineFWPaymentReceipt'. Cannot insert duplicate key in object 'tblTempOnlineFWPaymentReceipt'. The statement has been terminated. The statement has been terminated. The statement has been terminated.


But what is actually confusing me is that when I check the database the information is actually in it. I don't know why it's throwing up this particular error. Help

 
Old July 20th, 2007, 03:10 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Is your database set up with referential integrity? How is your sql inserting these records?

Kevin

dartcoach
 
Old July 20th, 2007, 03:39 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

That's a pretty terse question... What action are you taking that raises these errors? Are you sending the SQL directly, using one of the super gizmos .NET gives us, or what?

What is the actual action with respect to the DB?

You say the data are there. All of them? I mean, something failed...
 
Old July 20th, 2007, 08:13 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

What operation are you doing on the table tblTempOnlineFWCompany - Insert or Update.

The error would come when you insert a duplicate record to the table, that is, the table already has a record by the primary key you are inserting.

In that case, you would have the Primary Constraint violation error. A good technique would be to check the presence of your record by primary key and then insert the record if the record is not availab;e. If the record is already available in the table, you can update the record instead of insert

Cheers
Shasur




http://www.dotnetdud.blogspot.com
 
Old July 20th, 2007, 10:34 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I vote for the idea that your code is calling the database insert twice. That is the only explanation I see that could supports the legitimate presense of data but also the presense of an error reflecting a data insert problem which would result in no data.

What event are you handling that fires off the insert? Is it possible that this handler or the method that is actually doing the insert is being called twice?

-Peter
 
Old July 23rd, 2007, 01:54 PM
Authorized User
 
Join Date: Oct 2006
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for your replies. I found what was wrong:D

 
Old July 23rd, 2007, 09:52 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

And it was?
 
Old July 27th, 2007, 09:56 AM
Authorized User
 
Join Date: Oct 2006
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In the code in was running the procedure to enter a record id twice.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Violation of PRIMARY KEY constraint??? twyce C# 1 September 9th, 2008 01:23 AM
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
XSD composite key constraint aldwinenriquez XML 2 August 15th, 2005 04:20 AM
FOREIGN KEY and PRIMARY KEY Constraints junemo Oracle 10 June 15th, 2004 01:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.