caml查询如何返回null [英] how caml query returns null

查看:98
本文介绍了caml查询如何返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中有一个caml查询,以返回SharePoint列表的某些项目.我添加了IF语句,以防查询找不到任何匹配项或返回NULL.

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>
                                       <Eq>
                                          <FieldRef       Name='Department'/>
                                          <Value Type='Text'>"+Department+"</Value>                           </Eq></Where>"
                  });

                  foreach (SPListItem item in Items)
                  {
                      if (item != null)
                      {
                          item["Name"]="abcd";
                          item.Update();
                      }
                      else
                      {
                          newListItem["Name"] = "xyz";
                          newListItem.Update();
                      }
                  }


如果未在列表中找到Department,则不会转到ELSE语句.


if it not finds Department in the list, it doesn''t goes to ELSE statement.

推荐答案

您是否使用caml查询构建器尝试了该查询?我认为,在给那个可变的部门时,它会带来一些问题.只需删除该变量,然后将其包含在查询中即可,如下所示.

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.

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



现在,验证结果是否正确.如果不是,则整个查询都需要更改.如果是的话,那么当我们将变量插入查询中时就会出现问题.



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.


这篇关于caml查询如何返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆