0

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);
        }
3

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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