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