SPQuery with lookup columns returns no data

SPQuery with lookup columns returns no data

An SPQuery for lookup columns should be easy. Start the famous U2U Caml Editor, configure your query, and query the list.

image

This query will get a result if the lookup column stores something like “1;#1”. But if its value is e.g. “1;#Title”, the query will not return an item.

So what can we do about it?

Add a LookupId=’TRUE’ to your query, so it will look like this:

Remember to omit the Query tags from the U2U Caml Editor when pasting the query into your Visual Studio source code!

1 Comment

iFunky Application Development

Reply

I’ve been having probs with these damn Sharepoint queries, any benefits of doing SPContext.Current.Web.Lists[“meetings”] instead?

 

Leave a Reply