Click here to Skip to main content
15,909,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We have a asp.net web application database is sql server 2008 ,which is hosted in a server. Sometimes we face a problem like:-----
Suppose a user is inserting a record in a table. As per our coding one record should be inserted only once with an id as primary key. But sometimes the same record is being inserted twice with different id but other details remain exactly same.So far we have ruled out problem in coding and stored procedure,but we are unable to find the exact problem.
If anyone has faced similar situation,please give us some
solution.
Posted
Comments
__TR__ 26-Nov-12 6:19am    
One of the situations the scenario you described can occur is when the user double clicks a button instead of a single click. This causes the button click event to be fired twice and if there is some data inserted into the database in this event, it will get duplicated.
To avoid this you can hide your button through JavaScript when user clicks the button there by avoiding the double click.
dimpledevani 26-Nov-12 7:56am    
You can clear the values as soon as your insert query fires or disabl the button once its clicked.Debug your code and find out

definitely the problem is in your code.. You may be call stored procedure as well as inline query both. debug your application line by line thoroughly. you will definitely got whats wrong you have done. if still you wont find the mistake, then make your ID column to indentity false keep primary key as it is then execute. it will return u the error at 2nd time insertion.
 
Share this answer
 
Hi,

Looking at your post am able to kinda infer that there is some uniqueness problem.
But since primary key has been used on ID and records with different ID's, but similar details are being entered, you might want to use a CTE with delete option to eliminate the duplicate records.

Also you might want to alter the primary key to include ID plus some other relevant unique column.
 
Share this answer
 
Check your code..

Make sure you added
C#
command.ExecuteNonQuery()
only once....

Hope it helps
 
Share this answer
 
Comments
sanjay acharya 26-Nov-12 7:32am    
ya we have used command.ExecuteNotQuery() only once.
jaswinder Singh03 26-Nov-12 7:36am    
have you used ExecuteScalar etc. with ExecuteNonQuery. if yes remove it..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900