Click here to Skip to main content
12,894,930 members (58,007 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# CAML sharepoint2010
I have a caml query in my code to return some items of SharePoint list. I added the IF statement in case if query not find any matching item or returns NULL.
  SPListItemCollection Items = RiskAssesment.GetItems(new SPQuery()
                        Query = @"<Where>
                                            <FieldRef       Name='Department'/>
                                            <Value Type='Text'>"+Department+"</Value>                           </Eq></Where>"
                    foreach (SPListItem item in Items)
                        if (item != null)
                            newListItem["Name"] = "xyz";

if it not finds Department in the list, it doesn't goes to ELSE statement.
Posted 11-Oct-12 6:22am
Updated 11-Oct-12 7:24am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Did you tried that query with caml query builder? I think while giving that variable Department, it is giving some problem. Just remove that variable and include in the query as below.

          <FieldRef       Name='Department'/>
          <Value Type='Text'>Department</Value>                                       </Eq>

Now verify the result is coming correctly or not. If not then entire query need to be changed. If yes, then the problem coming when we insert that variable into the query.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170424.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100