Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have list of item objects in List<Items> itemList. Now I wan't to insert this in to the item table. One technique i did was, I delete all the existing items in the table and then insert the list. This get very slow. How can I save only the updated items in to the table.
Posted
Comments
Dave Kreskowiak 26-Mar-11 22:40pm    
You're going to have to show some code. If you've got a performance problem, it's impossible to diagnose with just a vague description like you've provided.

1 solution

There are many ways depending on your configurations, but based on what is described here, I would recommend that you add an IsDirty field to your items. Set the field to true when anything on the item changes. Then when you loop through the list you can check to see if the field is true and only update those items. This method requires that each item has an identifying field, a unique value for that item (typically an int or Guid). You would use this identifier to locate the row in the table for that item, and then update the information in that row.
 
Share this answer
 
Comments
sam_di 27-Mar-11 9:53am    
Thanks for the reply. When doing like this I faced another problem. That is user can remove any item from the list by using remove method. Then how can I identify and delete this from the table.
JOAT-MON 27-Mar-11 22:58pm    
Before you delete the item from your list, get the identifying field value from the item and use it to identify and delete the row from the table.

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