473,320 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Database PRIMARY KEY

hi,
i am new to programming and database. please help

when ever i am submitting the i am getting the ERROR "Violation of PRIMARY KEY constraint 'PK_property'. Cannot insert duplicate key in object 'dbo.property'. The statement has been terminated."

every time when i insert new data. and if i am removing primery key records entering two in database. whats the problem?

you can check the code

Protected Sub btn_submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_submit.Click
Try
Dim con As New SqlConnection
con.ConnectionString = "Data Source=72.18.129.86,1533;Initial Catalog=rockland;Database=rockland;Uid=udi;pwd=pwd ;"
con.Open()
Dim cmd As New SqlCommand
cmd.CommandText = "INSERT INTO property (...) VALUES ('" .... "')"
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.ExecuteNonQuery()
con.Close()
Label1.Visible = True
Label1.Text = "Submitted"

Catch ex As Exception
Label1.Text = ex.Message
End Try

End Sub


i am using sql server 2005
Nov 7 '07 #1
4 1361
r035198x
13,262 8TB
hi,
i am new to programming and database. please help

when ever i am submitting the i am getting the ERROR "Violation of PRIMARY KEY constraint 'PK_property'. Cannot insert duplicate key in object 'dbo.property'. The statement has been terminated."

every time when i insert new data. and if i am removing primery key records entering two in database. whats the problem?

you can check the code

Protected Sub btn_submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_submit.Click
Try
Dim con As New SqlConnection
con.ConnectionString = "Data Source=72.18.129.86,1533;Initial Catalog=rockland;Database=rockland;Uid=udi;pwd=pwd ;"
con.Open()
Dim cmd As New SqlCommand
cmd.CommandText = "INSERT INTO property (...) VALUES ('" .... "')"
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.ExecuteNonQuery()
con.Close()
Label1.Visible = True
Label1.Text = "Submitted"

Catch ex As Exception
Label1.Text = ex.Message
End Try

End Sub


i am using sql server 2005
But the exception is already telling you what the problem is.
You have to insert a record with a different Id everytime. Perhaps you should have defined your table with the id column set to auto increment if you don't want to supply the keys all the time.
Nov 7 '07 #2
debasisdas
8,127 Expert 4TB
The error message itself is self explanatory. If there is a primary key defined on any column of a table the data in that coumn must be unique and not null. Just try to follow that.
Nov 7 '07 #3
The error message itself is self explanatory. If there is a primary key defined on any column of a table the data in that coumn must be unique and not null. Just try to follow that.

very very thanks for your replies. now i set id to auto increment. but the problem is each record getting two times in database.(ex: id = 2 name =abc and id = 3 name = abc) when i am posting and i am clicking onces on the submit button . actual this is the problem from database can you please help me in these issue

Thanks in advance
Nov 7 '07 #4
r035198x
13,262 8TB
very very thanks for your replies. now i set id to auto increment. but the problem is each record getting two times in database.(ex: id = 2 name =abc and id = 3 name = abc) when i am posting and i am clicking onces on the submit button . actual this is the problem from database can you please help me in these issue

Thanks in advance
Are you sure the code for inserting the data is not being called twice?
Unless you've got a before/after insert trigger on the table which inserts the record again ...
Nov 7 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Cherrish Vaidiyan | last post by:
hello, Thanx for the suggestions on my Listener query. Now i am performing a simple work.. STANDBY DATABASE creation. I have followed the instraction from Oracle 9i Release 1 documentation...
0
by: Cherrish Vaidiyan | last post by:
sir, The following are the steps that i followed in setting up standby database on Red hat Linux 9. i am using Oracle 9i. i have followed the steps in this site : ...
0
by: Chris | last post by:
Hi, I am currently designing a simple service orders database. I have played around with MySQL a bit but this is the first time I'm using it in anger, I have a few design queries to make sure I am...
6
by: Clay Beatty | last post by:
When you create database diagrams in Enterprise Manager, the details for constructing those diagrams is saved into the dtproperties table. This table includes an image field which contains most of...
7
by: PC Datasheet | last post by:
Looking for suggestions ---- A database was designed for a national automobile inspection program. In it's simplest form, the database has two tables: TblOwner OwnerID <Year/Make/Model owned...
3
by: reageer | last post by:
Hi all, I have a design question: I have a bunch of users (name, address, zip, etc.). They are assigned a card with a specific id. The only thing unique is this card id, or probably the...
25
by: Colin McKinnon | last post by:
Hi all, There's lots of DB abstraction layers out there, but a quick look around them hasn't turned up anything which seems to met my requirements. Before I go off and write one I thought I'd...
76
MMcCarthy
by: MMcCarthy | last post by:
Normalisation is the term used to describe how you break a file down into tables to create a database. There are 3 or 4 major steps involved known as 1NF (First Normal Form), 2NF (Second Normal...
1
by: Utahduck | last post by:
I've been having some issues so forgive me if this double-posts. Because I have some large but static Filegroups within a database I prefer to backup my filegroups instead of everything at once. ...
0
by: Vinod Sadanandan | last post by:
STANDBY DATABASE MONITORING & PROTECION MODES (9iR2) This document is written for understanding and monitoring standby database configured with diffrent protection modes . MAXIMUM PROTECTION ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.