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);
        }
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, privacy policy and cookie policy

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