473,769 Members | 5,570 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 3828
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.ewsLin ksGroupRole.Con straints.AddRan ge(New
System.Data.Con straint() {New
System.Data.Uni queConstraint(" EwsLinksDSKey5" , New String()
{"roleId", "linkGroupI d"}, True)})
Me.EwsDS.ewsLin ksGroupRole.Tab leName = "ewsLinksGroupR ole"

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
3587
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 an existing username. I have a database full of the same usernames!
2
17871
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 anotherDB.dbo.table1 gives the following error: Violation of UNIQUE KEY constraint...
9
9585
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 this? Thanks, Bob C.
2
36261
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` int(10) unsigned NOT NULL auto_increment, `lastname` char(15) NOT NULL default '', `firstname` char(15) NOT NULL default '', `birthdate` date NOT NULL default '0000-00-00',
3
2340
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 some reference tables for conciseness), these being state, locality, street, street number, and address. The breakdown is roughly consistent with Australian addressing standards, we're working on finalising this. Because we carry the primary...
1
1204
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 output at all! Normally, psql either shows the constraint or reports that the constraint doesn't exist. (BTW, I know that the default clauses below are kind of weird, but I am using PG to process data for a database that doesn't use NULL and...
2
45879
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 and the corresponding model numbers (primary key on serial_numbers) Since Table A has no constraints duplicates may exist. Additionally, table A is actually an Excel spreadsheet that is maintained by an employee that records new hardware as...
4
3835
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 rule of the business is that only band plays on the one night. The SQL statement prevents a Band name being repeated (as it is Unique). Similar statement for the Venues. CREATE TABLE Bands (BandID varchar(5) CONSTRAINT BandID PRIMARY KEY, Band...
1
5969
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 fails,<'htbase_tst/kn_history_question', CONSTRAINT 'FK_kn_history_question_complaint' FOREIGN KEY ('complaint_id' ) REFERENCES 'complaint'('id')). This is my table script..... CREATE TABLE `city` ( `id` int(11) NOT NULL auto_increment, ...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10219
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.