CAML query OrderBy is not working
-
02-10-2020 - |
سؤال
SPWeb _SPweb = _SPSite.OpenWeb();
SPList _SPlist = _SPweb.Lists[FL.ToString()];
SPQuery _spquery = new SPQuery();
_spquery.Query = "<Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>now</Value></Eq></Where><OrderBy><FieldRef Name='Date_Of_x0020__Posted' Ascending='False' /></OrderBy></Query>";//"<Query><OrderBy><FieldRef Name='Date_Of_x0020__Posted' Ascending='false' /></OrderBy></Query>";///CAMLquery for oderby posted date
SPListItemCollection FaqCollection = _SPlist.GetItems(_spquery);
if (FaqCollection != null || FaqCollection.Count <= 0)
{
foreach (SPListItem item in FaqCollection)
{
}
}
Code above is retrieving the data from a list but not ordering, it was working perfectly, but it's not working any more. What have I missed here?
المحلول
I think the problem is with including Query tag in your CAML. Just remove it.
Here is a snippet that should work:
<Where>
<Eq>
<FieldRef Name="Title" />
<Value Type="Text">now</Value>
</Eq>
</Where>
<OrderBy>
<FieldRef Name="Date_Of_x0020__Posted" Ascending="False" />
</OrderBy>
نصائح أخرى
OK try this:
"now";
This should work
لا تنتمي إلى sharepoint.stackexchange