473,506 Members | 16,970 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot add primary key constraint since primary key is already set for the table

Hi,

I am getting the following error when I run my Visual Basic
application:

"Cannot add primary key constraint since primary key is
already set for the table"

I am using datasets with primary keys which are filled from
an SQL Server database. These datasets were automatically
generated in Visual Studio.

Now, the application worked fine for a while until I added
buttons onto a form. I did not touch any datasets or the
data in the database. I did not touch the file in which the
error is thrown.

Does anybody know what causes this error? I have searched
extensively on Microsoft and Google, and the only solution
I can find is to remove the primary key constraints in the
dataset. I would be grateful if there was another solution
to this rather frustrating problem.

Thankyou

Stephen.
Nov 20 '05 #1
1 3799
I have found 'a' solution to my problem.

In the form I added buttons to, I discovered two lines
which are probably at fault that were in the "Web Form
Designer Generated Code" part.

The following two lines added a constraint on one
particular table (even though my dataset has 5 more) which
obviously caused the problem as there is already a
constraint in the dataset itself.

Me.EwsDS.ewsLinksGroupRole.Constraints.AddRange(Ne w
System.Data.Constraint() {New
System.Data.UniqueConstraint("EwsLinksDSKey5", New String()
{"roleId", "linkGroupId"}, True)})
Me.EwsDS.ewsLinksGroupRole.TableName = "ewsLinksGroupRole"

Why these lines appeared, I do not know. Especially since
adding buttons that were not databound had caused it.

The following newsgroup article assisted me to pinpointing
a solution to my problem:
http://groups.google.com.au/groups?h...3DN%26tab%3Dwg

-----Original Message-----
Hi,

I am getting the following error when I run my Visual Basic
application:

"Cannot add primary key constraint since primary key is
already set for the table"

I am using datasets with primary keys which are filled from
an SQL Server database. These datasets were automatically
generated in Visual Studio.

Now, the application worked fine for a while until I added
buttons onto a form. I did not touch any datasets or the
data in the database. I did not touch the file in which the
error is thrown.

Does anybody know what causes this error? I have searched
extensively on Microsoft and Google, and the only solution
I can find is to remove the primary key constraints in the
dataset. I would be grateful if there was another solution
to this rather frustrating problem.

Thankyou

Stephen.
.

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3564
by: John Simmons | last post by:
How is it that even though I have the column "username" in my database set as a Primary key, using my PHP script to add new users to the database works without any errors even when signing up using...
2
17853
by: Caroline | last post by:
I want to add the content of a table into another I tried to copy all fields, except the primary key: INSERT INTO table2 (field2, field3, field4, ...) SELECT field2, field3, field4, ... FROM ...
9
9557
by: Bob C. | last post by:
I want to create a 1-many relationship. Parent table has a primary key, child table has no primary key. The child table does have an index with all four fields of the parent's PK. How can I do...
2
36240
by: Ralph Smith | last post by:
I'm having trouble copying a database to another machine. Here are the two table's in ths database and the sql commands: DROP TABLE IF EXISTS `clients`; CREATE TABLE `clients` ( `client_id`...
3
2325
by: William D. Bartholomew | last post by:
I'm working on a system that is very address-centric and detection of duplicate addresses is very important. As a result we have broken addresses down into many parts (DDL below, but I've left out...
1
1180
by: Kevin Murphy | last post by:
Using PG 7.4.5 on Mac OS X 10.3 ... I have a primary key that I can't destroy and can't create. One weird symptom is that when I use \d in psql to attempt to display the constraint, there is no...
2
45849
by: mivey4 | last post by:
Okay I have 2 tables: Table A - holds a list of new hardware serial numbers and their corresponding model (no constraints or indexes) Table B - holds a distinct list of current serial numbers...
4
3816
by: Peter | last post by:
I am interested in informed feedback on the use of Constraints, Primary Keys and Unique. The following SQL statement creates a Bands tables for a database of bookings Bands into Venues, where the...
1
5951
by: nitinkhare1 | last post by:
Please help,I'm very frustated. when I ADD the data in kn_history_question table of htbase_tst database....it giving the error "Cannot add or update a child row:a foreign key constraint...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.