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

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
            returnVar.Add(n);
        }
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 e-junkie-chronicles.blogspot.co.uk/2011/06/… –  Hugh Wood Nov 21 '12 at 16:58
    
Also this from my bookmarks for you. blog.solanite.com/keith/Lists/Posts/Post.aspx?ID=15 –  Hugh Wood Nov 21 '12 at 17:00
add comment

1 Answer 1

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
add comment

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.