Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

1.)

SPListItemCollection collec1= dt as SPListItemCollection;

2.)

  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

2 Answers 2

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

Also check following link for the code details:

http://social.technet.microsoft.com/Forums/sharepoint/en-US/f772b759-28b7-4330-b4a2-ef7541f3e79c/how-to-convert-datatable-into-splistitemcollection

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 at 6:35
    
Nope dude check DataTable class [msdn.microsoft.com/en-IN/library/system.data.datatable.aspx]. 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 at 6:45
    
you can also check the details of SPListItemCollection.GetDataTable() (msdn.microsoft.com/en-us/library/…). Its basically a converter. –  Ravi Ranjan May 15 at 6:51
    
Thanks for this information ravi –  luckydeveloper May 15 at 6:57
    
Hit the response as answer if that suffices you as answer. –  Ravi Ranjan May 15 at 7:07

Your Answer

 
discard

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.