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

G

Guest

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.
 
G

Guest

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(New
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?...s+already+set+for+the+table&meta=&sa=N&tab=wg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top