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'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?

Thanks

share|improve this question
1  
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 1

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

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

  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

 
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.