x

duplicate data

Hey I have work with c# and Sql server for awhile but never had to build anything from start-up. I created a database with basic stored procedure. insert, update, and delete basic stuff.

I have a problem with duplicate records.
I have two tables tb1 and tb2 in these tables are the system number and project name. Every web form has two drop down list that is populate with this data. tb1 = project names and tb2 = system numbers.

When they click the save button the data is save but, tb1 has a new entry with duplicate project name and tb2 has a duplicate with system name each receives a new pk number.

I tried validation check if exist get error can't modified existing pk.
or doesn't save.

I have pk and fk on each table connected to tb1 and tb2.

any help any one can give is appreciated.

If I can get example code a link to reference(any thing) :confused

ok.. here we go.

tb1 
pid int indentity (1,1) pk
projectname

tb2
sid int indentity (1,1) pk
pid int fk
systemnumbers

tb3
cid int indentity (1,1) pk
pid int fk
sid int fk
cname
caddress
ccity
cstate
czip
more ▼

asked Sep 01 '10 at 07:50 AM in Default

postonoh gravatar image

postonoh
205 14 21 22

Probably you have problem in the insert(update) stored procedures. Post the code of them here. Also Let us know which one are called when you press the save button.
Sep 01 '10 at 08:53 AM Pavel Pawlowski
(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

Your problem is caused by the fact that your procedure needlessly tries to insert new project record in tb1 and new system record in tb2. This action is not needed at all as these tables are your catalogs, your users don't need to insert new records in these. Your webforms have 2 dropdowns which are populated with

  • project name (as display property) and perhaps pid as value property of the dropdown values
  • system number information which is dependent on the project.

When you save data, you only need to insert tb3, that is all. You get pid from the value of the selected item of the first dropdown, and sid from the value of the selected item of the second dropdown.

Hope this helps,

Oleg
more ▼

answered Sep 01 '10 at 08:50 AM

Oleg gravatar image

Oleg
15.9k 2 4 24

(comments are locked)
10|1200 characters needed characters left

Thanks figure out my problem. It was a c# code problem I was actually having the drop down list connected to the project name instead to the pid and displaying the name. stop my duplicate insert.

thanks.
more ▼

answered Sep 10 '10 at 12:33 PM

postonoh gravatar image

postonoh
205 14 21 22

@postonoh, if Oleg resolved this for you, please mark his answer as the accepted one. The button is on the left side of the page at the top of his post.
Sep 10 '10 at 12:57 PM Mark
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x977
x103

asked: Sep 01 '10 at 07:50 AM

Seen: 882 times

Last Updated: Sep 02 '10 at 12:49 AM