Click here to Skip to main content
15,908,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a list box . I want that when submit is clicked then all the items added into the database except those which present in the database previously . All the items have productid and adminid which enters with them .

For example , i have product 1,2,3,4 for admin 1 and product 3 is already present in table for admin 1 then product 1,2,4 will be added and 3 will not as it is already added for admin 1 .
Posted
Updated 30-Oct-11 23:17pm
v3
Comments
Sander Rossel 31-Oct-11 3:27am    
What tools are you using to communicate with the database?
Amir Mahfoozi 31-Oct-11 3:29am    
Do you want the sql or the c# code ? and are you using an ORM or use direct access to DB ?
Vimalrashamra 31-Oct-11 3:32am    
i want the insertion code in ado.net

1st but not the best solution may be, you first check in table by query that either it is already saved or not. which is time taking.
secondly, why don't you apply composite unique key constraint on both of the columns..that if prodID will repeat for admin-id.. do not let it save it in database and catch the exception with empty body... :)

for second solution, you require to only to make change in table structure by applying composite key constraint on table and in code end only to handle database call within try block with empty catch block.
 
Share this answer
 
v2
 
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