Take the 2-minute tour ×

I'm using SPListItemCollection.GetDataTable to return the list search results. The GetDataTable doesn't contain all the columns that are mentioned in ViewFields, but I can see all those columns in SPListItemCollection.Xml property. Columns like AverageRating are missing. Is this a known issue?

I'm using datatable for doing some filtering and row operations on the returned result as it is easier to do with a datatable. Now I'm planning to create dataset from SPListItemCollection.Xml and return the datatable from there. Is there a better approach?


share|improve this question
plz post your code so i'll you provide perfect solution.. –  Hitesh Chandegara Jan 19 '13 at 10:05
Code is like below..I have tested by writing the items.Xml and items.GetDataTable to an xml file. I can see that xml returned by GetDataTable doesn't contain the rating columns. SPListItemCollection items = list.GetItems(spQuery) return items.GetDataTable(); –  Rajesh Jan 21 '13 at 9:03
I think also that the columns are not selected in the query. –  Sascha Jan 6 at 6:51
add comment

1 Answer

try this code... it'll work perfectly in my system.

  SPQuery query = new SPQuery();
  query.Query = string.Concat(
                            "<FieldRef Name='Status'/>",
                            "<Value Type='CHOICE'>Not Started</Value>",

  query.ViewFields = string.Concat(
                                  "<FieldRef Name='Title' />",
                                  "<FieldRef Name='StartDate' />",
                                  "<FieldRef Name='DueDate' />",
                                  "<FieldRef Name='Priority' />");

  query.ViewFieldsOnly = true; 

   SPListItemCollection oItem = splist.GetItems(query);
   DataTable objDatatable =   oItem.GetDataTable();

plz dont forget to apply query.ViewFieldsOnly = true;

Hope it helps.... :D

share|improve this answer
add comment

Your Answer


