Click here to Skip to main content
11,934,380 members (55,083 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 7:22am
Edited 11-Oct-12 8: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
Web02 | 2.8.151126.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2015
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