I have already created a webpart to show the data from list, but I really want is to only show top 5 records from that list (by using CAML query).
Does anyone know how to do this? Many thanks.
<Query>
<OrderBy>
<FieldRef Name='ID' Ascending='False' />
</OrderBy>
</Query>
Select the list or library for which you want to write the query. Once you select the list, click on the New query button or Query with ViewFields button to build your CAML query.
CAML (Collaborative Application Markup Language) is an XML-based query language that helps you querying lists and libraries in SharePoint. This windows application has been developed to ease the work of a SharePoint 2013 and SharePoint Online developer. This tool will help you create and test your CAML Queries.
There is no option for case sensitivity in caml queries.
You could set the RowLimit property of your SPQuery object.
The <RowLimit>
tag is in the schema definition of a view (direct child of <View>
) and therefore cannot be nested inside a <Query>
tag.
The below code shows top 5 records from the list (by using CAML query).
SPQuery spQuery = new SPQuery();
spQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='FALSE'/></OrderBy>";
spQuery.RowLimit = 5;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With