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 use a SPQuery to get a list of 100 items. I then loop round the list and get the values of the SPListItem

e.g. string name = mySPListItem["Name"].ToString(); (VERY SLOW)

This runs a lot slower than converting the SPListItemCollection to a datatable (SPListItemCollection.GetDataTable()) and then looping over each datarow.

e.g. string name = myDataRow["Name"].ToString(); (VERY FAST)

Can anyone explain why this is?

More code as requested.

        foreach (System.Data.DataRow dr in nListItemCollection.GetDataTable().Rows)
            returnVar.Add(new myObj(dr)); //Fast

        SPListItemCollection items = mySPList.Items;
        foreach (SPListItem dr in items)
            SPListItem li = dr;
            myObj n = new myObj(li); //Slow
share|improve this question
Can you post the loop code where you iterate through the items? that is usually where the problem lies. – Dave Wise Nov 21 '12 at 16:46
@James Love, I believe this one is on your blog… – Hugh Wood Nov 21 '12 at 16:58
Also this from my bookmarks for you. – Hugh Wood Nov 21 '12 at 17:00
up vote 0 down vote accepted

To explain it simply, the SP version needs to do quite a bit more to get a column value than when all columns/rows are retrieved at once and parsed as a native c# DataRow.

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.