In Blogs
The QPSiteDataQuery object enables you to describe a query performed across multiple lists, which may be located in multiple web sites in the same Web site collection.
One of the major features is that all queries that are performed trough this object are cached. This means that when you perform the query multiple times on the same data you’ll experience better performance than using a object that does not use data caching.
Like most of the WSSMOSS query objects, you’ll have to configure the query object by using CAML.
Recently I got a question why the SPSiteDataQuery object was not returning data, although there were enough records that would match the query.
For example: Suppose you have a simple custom list in WSS/MOSS that contains just two fields
1. Title
2. Email address
This list contains the following records:
User A; user_a@domain.com
User B; user_b@domain.com
User C;
As you can see in the list above, User C has no filled in email address.
To query this list you could configure the SPSiteDataQuery object as below:
SPList list = web.Lists["Testlist"];
SPSiteDataQuery query = new SPSiteDataQuery();
query.Lists = string.Format("<Lists><List ID=’{0}’/></Lists>", list.ID);
query.ViewFields = "<FieldRef Name=’Email’ />";
query.RowLimit = 25;
 
As you can see I defined the ViewFields property to display the email field. But what will happen when the field in question has no data entered by the user, as User C in our example? When the query hits a field with no data entered by the user it will abort the query completely and will not return any records. Why not just skipping the records that do not match the query? I don’t know, but the good news is that you can configure the query to display all results even if a so called �null-value’ is being encountered.
How to accomplish this? Just change the ViewFields property by adding a �nullable=true’ attribute to the CAML syntax.
query.ViewFields = "<FieldRef Name=’Email’ Nullable=’True’ />";

Et voila. Now you have the results that you expected in the first place.

Laat uw reactie achter

Vul je zoekopdracht in.