谁能告诉我这个 caml 查询代码有什么问题吗?

发布于 2024-11-10 15:03:41 字数 2838 浏览 6 评论 0原文

查询:

<Where>
  <Eq>
    <FieldRef Name='Document Type' LookupId='True' />            
    <Value Type='Text'>Standards(STA)</Value>
  </Eq>
</Where>
<OrderBy>
 <FieldRef Name='Number' Ascending='False'/>
</OrderBy>
<RowLimit>1</RowLimit>"

代码上下文:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Page Language="C#" inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register tagprefix="WebPartPages" namespace="Microsoft.SharePoint.WebPartPages" assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<html>

<head>
<meta name="WebPartPageExpansion" content="full" />
<meta name="ProgId" content="SharePoint.WebPartPage.Document" />


<h1>T-Site</h1>

 <script runat="server" type="">            

protected void sevak(object sender, EventArgs e)

string lastitem;
try
{

  using (SPSite objsite = new SPSite("http://..."))
  {
    using (SPWeb objWeb = objSite.OpenWeb())
    {
      SPList objList = objWeb.Lists["...."];
      SPQuery objQuery = new SPQuery();

      objQuery.Query = "<Where><Eq><FieldRef Name='Document Type' LookupId='True' />            <Value Type='Text'>Standards(STA)</Value></Eq></Where><OrderBy><FieldRef Name='Number' Ascending='False'/></OrderBy><RowLimit>1</RowLimit>";

      objQuery.Folder = objList.RootFolder;
      SPListItemCollection colItems = objList.GetItems(objQuery);

      if (colItems.Count>0)
      {
        lastitem=colItems(0);
      }
      else 
      { 
        Label1.Text="noItem";
      }
    }
  }
}
catch (Exception ex)
{
  return ex;
}

Label1.Text= "lastitem";

<SharePoint:CssLink runat="server"></SharePoint:CssLink>
<SharePoint:ScriptLink runat="server" language="javascript" name="core.js">

</SharePoint:ScriptLink>

<body>

<form id="form1" runat="server" action="Page-2.aspx">
<p>


<asp:Button runat="server" Text="Submit" id="Button1" OnClick="sevak" ></asp:Button>


</p>
<p><asp:Label runat="server" id="Label1"></asp:Label></p>
</form>
</body>


</html>

The Query:

<Where>
  <Eq>
    <FieldRef Name='Document Type' LookupId='True' />            
    <Value Type='Text'>Standards(STA)</Value>
  </Eq>
</Where>
<OrderBy>
 <FieldRef Name='Number' Ascending='False'/>
</OrderBy>
<RowLimit>1</RowLimit>"

Code Context:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Page Language="C#" inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register tagprefix="WebPartPages" namespace="Microsoft.SharePoint.WebPartPages" assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<html>

<head>
<meta name="WebPartPageExpansion" content="full" />
<meta name="ProgId" content="SharePoint.WebPartPage.Document" />


<h1>T-Site</h1>

 <script runat="server" type="">            

protected void sevak(object sender, EventArgs e)

string lastitem;
try
{

  using (SPSite objsite = new SPSite("http://..."))
  {
    using (SPWeb objWeb = objSite.OpenWeb())
    {
      SPList objList = objWeb.Lists["...."];
      SPQuery objQuery = new SPQuery();

      objQuery.Query = "<Where><Eq><FieldRef Name='Document Type' LookupId='True' />            <Value Type='Text'>Standards(STA)</Value></Eq></Where><OrderBy><FieldRef Name='Number' Ascending='False'/></OrderBy><RowLimit>1</RowLimit>";

      objQuery.Folder = objList.RootFolder;
      SPListItemCollection colItems = objList.GetItems(objQuery);

      if (colItems.Count>0)
      {
        lastitem=colItems(0);
      }
      else 
      { 
        Label1.Text="noItem";
      }
    }
  }
}
catch (Exception ex)
{
  return ex;
}

Label1.Text= "lastitem";

<SharePoint:CssLink runat="server"></SharePoint:CssLink>
<SharePoint:ScriptLink runat="server" language="javascript" name="core.js">

</SharePoint:ScriptLink>

<body>

<form id="form1" runat="server" action="Page-2.aspx">
<p>


<asp:Button runat="server" Text="Submit" id="Button1" OnClick="sevak" ></asp:Button>


</p>
<p><asp:Label runat="server" id="Label1"></asp:Label></p>
</form>
</body>


</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千紇 2024-11-17 15:03:41

我认为问题在于字段引用“文档类型”:

  1. FieldRef 元素需要引用字段的内部名称。如果“文档类型”列是通过 UI 创建的,则该列的内部名称为“Document_x0020_Type”。

  2. 您指定的 LookupId="True" 会导致针对查找字段的 ID 进行查找,但您提供了文本值。根据您的字段类型,您应该提供文档类型的数字 ID,或者省略 LookupId="True" 部分以针对查找字段的文本进行查询。

I think the problem is the field reference "Document Type":

  1. The FieldRef elements expects an internal name of the referenced field. If the column "Document Type" was created via the UI the internal name of this column is "Document_x0020_Type".

  2. You specifed LookupId="True" which causes a lookup against the id of a lookup field, but you provided a text value. Depending of your field type you should either provider the numeric ID of the document type or omit the LookupId="True" part to query against the text of the lookup field.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文