Home > SharePoint > CAML Query WHERE Clause not working and returning all records

CAML Query WHERE Clause not working and returning all records


One thing I found about CAML query in SharePoint Development is when you put WHERE Clause in query it still returns all records.

For example:


SPQuery query = new SPQuery();
query.Query =
“<Query><Where></Where></Query>”

Here is the Fix:

Remove the “<Query> Tag and rewrite it

SPQuery query = new SPQuery();
query.Query =
“<Where></Where>”

 

This should fix it .

 


 

Advertisements
Categories: SharePoint Tags: ,
  1. Khaniya
    May 31, 2011 at 8:01 pm

    Thanks for sharing
    I have wasted 2 hr of time to get this solution

    Thanks again

  2. Alex
    August 2, 2012 at 2:06 pm

    I remove the / Still it return all fields

    • August 2, 2012 at 5:38 pm

      Can you please send me your query?

      Thanks

  3. chintan
    August 31, 2012 at 9:59 am

    My query also return all records. Pls. advice

    “Steve”;

    • October 5, 2012 at 6:08 pm

      Can you please send me your query.
      Thanks

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: