Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
I am doing online purchasing project.As i am stored product name in my Product Table.Example i have Product Name is Pen.but i want this product insert only one time on the product table. how reduce the duplication.

Please help me !!!
Posted
Updated 22-Feb-14 2:58am
v4
Comments
CHill60 22-Feb-14 8:59am    
You need to post the code you're using to insert the product, also do you have any indexes on the Product table?

Try with giving it a Product ID, that must be unique to the each product in your database.
In you code while inserting new Product, catch the exception as follows
C#
try
{
    /*
    Some code for inserting record
    */
}
catch(SqlException ex)
{
    if (ex.Number == 2627)
    {
        MessageBox.Show("Productis already there!");
    }
}

Error Number 2627 for MS-SQL server is for the violation of Unique-Key
Constraint.


-KR
 
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