I have a listview binded from a sql DB table with column1, column2, column3, I want to copy all the listview items in a sharepoint 2010 list column1, column2, column3 programmatically PS : sharepoint list have additional columns: column4, column5 and in the listview items are refreshed so when an item is deleted from listview it have to be deleted from the list too. I m gathering some idea, if it's feasable or not thanks
-
You mean both should be in sync?Amal Hashim– Amal Hashim2016-09-01 12:41:29 +00:00Commented Sep 1, 2016 at 12:41
-
exactly, because I want to bring some items from DB in column1, 2 and 3 , and the user put comment in column4 and column5, and when the item is deleted from DB, all the row is deleted from listBKChedlia– BKChedlia2016-09-01 12:43:53 +00:00Commented Sep 1, 2016 at 12:43
-
how many items aprox? Can you work on SQL Server side building a trigger?Juan Pablo Pussacq Laborde– Juan Pablo Pussacq Laborde2016-09-01 12:51:41 +00:00Commented Sep 1, 2016 at 12:51
-
it's about a 100 rows, PS : I have a listview webpart who bring the information, but I don't know how to copy specific column in it to my sharepoint listBKChedlia– BKChedlia2016-09-01 12:54:06 +00:00Commented Sep 1, 2016 at 12:54
1 Answer
You can create an External Event Receiver. That basically monitors external objects in your case its a SQL DB Table.
Inside the event receiver you can write code using SharePoint Object Model to Add/Update/Delete corresponding List Items.
Update - Above is valid only for SP 2013 and above
For SharePoint 2010 you are only option seems polling the SQL table in regular intervals and looking for changes. This will be tedious process because you don't know which item got changed. Polling logic can be done in a SharePoint custom Timer Job.
You can enhance performance by adding a last modified field in your SQL table and use that to sync between SPList and SQL Table.