SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider the following code:-

SPListItemCollection collListItems = emp_info.GetItems(query);
dt = collListItems.GetDataTable();

Now i want to convert the dt object back to SPListItemCollection object

Is this possible in one of the following ways


SPListItemCollection collec1= dt as SPListItemCollection;


  SPListItemCollection collec1= (SPListItemCollection)dt;

If not is there any other way where i can convert DataTable object back to a SPListItemCollection object.

Anyone with any ideas, Thanks....

share|improve this question

You have to iterate through DataTable and fill into SPListitemCollection object.

Also check following link for the code details:

share|improve this answer

The above mentioned techniques would have only work if DataTable would have been derived from SPListItemCollection.

Since its not the case, so you will have to iterate over the rows in DataTable and will have to create list items for each row and associate it with appropriate properties.

share|improve this answer
But the datatable is derived from SPListItemCollection – luckydeveloper May 15 '14 at 6:35
Nope dude check DataTable class []. When you execute method collListItems.GetDataTable(); it internally creates a new DataTable object and creates DataRow for all your listItems and add those rows into the DataTable. And this DataTable is returned as an object. – Ravi Ranjan May 15 '14 at 6:45
you can also check the details of SPListItemCollection.GetDataTable() (…). Its basically a converter. – Ravi Ranjan May 15 '14 at 6:51
Thanks for this information ravi – luckydeveloper May 15 '14 at 6:57
Hit the response as answer if that suffices you as answer. – Ravi Ranjan May 15 '14 at 7:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.