Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi folks,

when i insert data,
if the same data is in the table then i want error msg.
how can i do these.
Posted
Comments
Venkatesh Mookkan 14-Feb-11 21:21pm    
You question is too vanilla. You should mention what you did and where you are having the problem.
[no name] 15-Feb-11 0:39am    
Please be specific what is your requirement?
Ashishmau 15-Feb-11 4:09am    
If u have primary key column...then simple use try catch and write youe error message.

It really depends upon what you consider 'duplicate' data.

If you have just one field that should not be a duplicate what you need to do is to set that field as a primary key.

If you have two or three fields like this, create a composite primary key.

Then when you try to enter duplicate values. the database will automatically generate error messages.
 
Share this answer
 
You need to handle that on your own. Before you insert the data, query if exact data exist, if you found a match then you need to return an error, else you are good to insert the data.
 
Share this answer
 
till what I understood from your problem, is u don't want duplicate entry in your table.

If so then use unique constraint on a column.
 
Share this answer
 
You can either handle it from back-end or front-end. Let suppose you wanna do it from fron-end then before inserting data, you can check for duplicate records. In order to compare values, one possible way is to get data from database in a DataSet, create a DataView, insert data from DataSet to DataView object, and apply .RowFilter property of DataView. Now your DataView has filtered data. Get this filtered data in any variables and now you can compare it with your values.

Hope it will work.
 
Share this answer
 

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