469,645 Members | 1,634 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

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 3561
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by John Simmons | last post: by
3 posts views Thread by William D. Bartholomew | last post: by
4 posts views Thread by Peter | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.