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

I am trying to use GetDataTable on an SPListItemCollection. I have run into a situation where my SPFieldLookupValueCollections in this list are being converted to a string when they are stored in the DataTable.

Is it possible for me to store these values as SPFieldLookupValueCollections objects instead of strings?

share|improve this question
Yeah I asked a similar question a while ago. TL;DR Write your own GetDataTable method (which is what you found out also it seems). – Kit Menke Mar 26 '12 at 19:58

Apparently this is a known issue. I ended up using the following method that I found here, to resolve the issue:

    DataTable CreateDataTableFromListItemCollection(SPListItemCollection itemCollection)
        DataTable tbl = new DataTable();
        if (itemCollection.Count > 0)
            tbl.TableName = itemCollection[0].ParentList.Title;

        if (itemCollection.Count > 0)
            // Take the first item and generate all columns
            //tbl.TableName = itemCollection[0].Title;
            foreach (SPField curField in itemCollection.Fields)
                DataColumn col = new DataColumn(curField.InternalName);
            foreach (SPListItem item in itemCollection)
                DataRow row = tbl.NewRow();
                foreach (SPField field in itemCollection.Fields)
                        row[field.InternalName] = item[field.InternalName];
                    catch { continue; } // Gah...
        return tbl;

Hope this helps someone!

share|improve this answer

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.