如何使用连接查询中的数据在 Sharepoint 中创建数据视图?

发布于 2024-07-12 10:22:00 字数 1361 浏览 9 评论 0原文

我在 Sharepoint 中有 3 个列表。

我想创建一个由 3 个表连接而成的数据视图。

Table1 与 FieldA 上的 Table2 连接 表 2 在 FieldB 上联接到表 3,

表 1 在 FieldA 中具有重复值,因此我只需返回一个值即可与表 2 联接。

在 Access 中我的查询如下所示: 选择不同的 WRK_InputWorkOrders.WorkOrder、Production1.[零件编号]、Production1.[工单]、Production1.Location、StationItems.Station、Production1.Description、Production1.Revision、WRK_InputWorkOrders.Status FROM StationItems INNER JOIN (WRK_InputWorkOrders INNER JOIN Production1 ON WRK_InputWorkOrders.WorkOrder = Production1.[工单]) ON StationItems.Item = Production1.[零件编号] WHERE (((WRK_InputWorkOrders.Status)<>“已关闭”));

有没有办法为数据视图编写类似 sql 的查询?

我有 Sharepoint Designer 2007 和 Access。

目标是获取用户可以在 Internet Explorer 中查看的报告。 我尝试过使用方法。 但它返回重复的记录 我发现建议。 它建议使用 XPath 过滤器 not(@yourvalue = previous-sibling::dfs:YourRepeatingRowName/@yourvalue)

但无法让它工作。 我不知道要输入什么作为 YourRepeatingRowName

我发现 链接。 有谁知道它是否可以用来执行这样的连接?

I have 3 Lists in Sharepoint.

I want to create a dataview that is a join of 3 tables.

Table1 is joined with Table2 on FieldA
Table 2 is joined to Table3 on FieldB

Table1 has duplicate values in FieldA so I need to only return one value to join with Table2.

In Access my query looks like this:
SELECT DISTINCT WRK_InputWorkOrders.WorkOrder, Production1.[Part Number], Production1.[Work Order], Production1.Location, StationItems.Station, Production1.Description, Production1.Revision, WRK_InputWorkOrders.Status
FROM StationItems INNER JOIN (WRK_InputWorkOrders INNER JOIN Production1 ON WRK_InputWorkOrders.WorkOrder = Production1.[Work Order]) ON StationItems.Item = Production1.[Part Number]
WHERE (((WRK_InputWorkOrders.Status)<>"closed"));

Is there a way to write sql-like queries for dataviews?

I have Sharepoint Designer 2007 and Access.

The goal is to get a report that a user can view in Internet Explorer.
I have tried using this method. But it returns duplicate records
I found this suggestion. It suggests using an XPath Filter
not(@yourvalue = preceding-sibling::dfs:YourRepeatingRowName/@yourvalue)

But wasn't able to get it to work. I don't know what to enter as YourRepeatingRowName

I found this link. Does anyone know if it can be used to perform such a join?

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

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

发布评论

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

评论(5

惜醉颜 2024-07-19 10:22:00

您的问题更多的是 ADO.NET 问题。 不幸的是,ADO.NET 没有一种简单的方法来做到这一点,这就是为什么像amboa Solutions这样的公司构建他们的交叉列表Web部件:
http://store.bamboosolutions.com/pc- 42-1-cross-list-web-part.aspx

否则我会尝试使用 LINQ 来查询表。 这样做你可能会更幸运。

这是 MS 提供的 JOIN 查询的示例(我只更改了前两行 DataTable 来表示使用 SPListItemCollection 对象填充 DataTable)

DataTable orders = spListCol1.ToDataTable();
DataTable details = spListCol2.ToDataTable();

var query =
    from order in orders.AsEnumerable()
    join detail in details.AsEnumerable()
    on order.Field<int>("SalesOrderID") equals
        detail.Field<int>("SalesOrderID")
    where order.Field<bool>("OnlineOrderFlag") == true
    && order.Field<DateTime>("OrderDate").Month == 8
    select new
    {
        SalesOrderID =
            order.Field<int>("SalesOrderID"),
        SalesOrderDetailID =
            detail.Field<int>("SalesOrderDetailID"),
        OrderDate =
            order.Field<DateTime>("OrderDate"),
        ProductID =
            detail.Field<int>("ProductID")
    };

DataTable orderTable = query.CopyToDataTable(); 

Your question is more of an ADO.NET question. Unfortunately ADO.NET doesn't have an easy way to do this, which is why companies like bamboo Solutions builds theirCross List Web Part:
http://store.bamboosolutions.com/pc-42-1-cross-list-web-part.aspx

Otherwise I would attempt to use LINQ to query the tables. You might have more luck doing that.

Here is an example of a JOIN query provided by MS (I only changed the first two DataTable lines to represent filling a DataTable with an SPListItemCollection object)

DataTable orders = spListCol1.ToDataTable();
DataTable details = spListCol2.ToDataTable();

var query =
    from order in orders.AsEnumerable()
    join detail in details.AsEnumerable()
    on order.Field<int>("SalesOrderID") equals
        detail.Field<int>("SalesOrderID")
    where order.Field<bool>("OnlineOrderFlag") == true
    && order.Field<DateTime>("OrderDate").Month == 8
    select new
    {
        SalesOrderID =
            order.Field<int>("SalesOrderID"),
        SalesOrderDetailID =
            detail.Field<int>("SalesOrderDetailID"),
        OrderDate =
            order.Field<DateTime>("OrderDate"),
        ProductID =
            detail.Field<int>("ProductID")
    };

DataTable orderTable = query.CopyToDataTable(); 
凡间太子 2024-07-19 10:22:00

Microsoft 有一个视频演示和一篇文章,可能正是您想要的:

在单个数据视图中显示来自多个源的数据
http://office.microsoft.com/en-us/sharepointdesigner/HA103511401033。 aspx

使用 Microsoft Office SharePoint Designer 2007,您可以链接两个或多个包含相关数据的数据源,然后创建一个数据视图来显示这些链接数据源中的数据。

Microsoft has a video demo and a writeup that may be just what you want:

Display data from multiple sources in a single Data View
http://office.microsoft.com/en-us/sharepointdesigner/HA103511401033.aspx

With Microsoft Office SharePoint Designer 2007, you can link two or more data sources that contain related data and then create a single Data View that displays data from those linked data sources.

夏末染殇 2024-07-19 10:22:00

您想在 SharePoint Designer 中显示查询结果吗? 我相信SPD已经合并了数据源。 调查一下。

you want to show the query result in SharePoint Designer? I believe, SPD has merged data sources. Look into that.

别在捏我脸啦 2024-07-19 10:22:00

我发现第三部分添加了

Enesys RS 数据扩展允许您从任何 SharePoint 列表查询(检索、联接、合并……)数据,并使用结果构建“Reporting Services”报告,就像处理任何其他数据源一样。 http://www.enesyssoftware.com/

我无法使用它,因为我当前正在运行基本版使用内部数据库的 Sharepoint 版本。

I found this third part add on

Enesys RS Data Extension lets you query (retrieve, join, merge,...) data from any SharePoint list and use the result for building "Reporting Services" reports as you would do with any other data sources. http://www.enesyssoftware.com/

I can't use it because I am currently running the basic Sharepoint version that uses the internal database.

羅雙樹 2024-07-19 10:22:00

我已经做了类似的事情,但我无法使用数据视图。 我最终编写了一个自定义 Web 部件来完成此操作。 方法是:

  1. 使用 SPQuery 对象获取每个列表的 SPListItemCollection。 使用 CAML 查询来限制返回的项目。
  2. 使用 SPListItemCollection 对象的 GetDataTable() 方法检索每个列表的 ADO.NET DataTable 对象。
  3. 将表添加到 DataSet 对象。
  4. 创建表之间的关系。
  5. 使用 DataListRepeater 或其他任何方式呈现数据。

下面是一些显示大致流程的代码:

protected DataTable GetDataTableFromQuery(string camlQry, SPList theList) {
  SPQuery listQry = new SPQuery();  
  listQry.Query = camlQry;  
  SPListItemCollection listItems = theList.GetItems(listQry);  
  return listItems.GetDataTable();
}

protected void BuildDataSet() {  
  // get SPList objects for the lists in questions ... left as an exercise for the dev -- call them list1, list2, and list3  
  string camlQry = "the CAML necessary to retreive the ites from list1";  
  DataTable table1 = GetDataTable(camlQry, list1);  
  table1.TableName = "Table1";  
  camlQry = "the CAML necessary to retreive the ites from list2";  
  DataTable table2 = GetDataTable(camlQry, list2);  
  table1.TableName = "Table2";  
  camlQry = "the CAML necessary to retreive the ites from list3";  
  DataTable table3 = GetDataTable(camlQry, list3);  
  table1.TableName = "Table3";  

  // now build the DataSet
  DataSet ds = new DataSet();  
  ds.Tables.Add(table1);  
  ds.Tables.Add(table2);  
  ds.Tables.Add(table3);  
  ds.Relations.Add("Table1_2", ds.Tables["Table1"].Columns["FieldA"], ds.Tables["Table2"].Columns["FieldA"]);  
  ds.Relations.Add("Table2_3", ds.Tables["Table2"].Columns["FieldB"], ds.Tables["Table3"].Columns["FieldB"]);  

  // now you can do something with these, like store them in the web part class and bind them to repeaters in the web part's Render() method
}

I've done something like this, but I wasn't able to use a dataview. I ended up writing a custom web part to do it. The approach was:

  1. Use an SPQuery object to get an SPListItemCollection for each list. Use the CAML query to restrict the items returned.
  2. Use the SPListItemCollection object's GetDataTable() method to retrieve an ADO.NET DataTable object for each list.
  3. Add the tables to a DataSet object.
  4. Create relationships between the tables.
  5. Render the data however you like, using DataList or Repeater or whatever.

Here's some code that shows the broad strokes:

protected DataTable GetDataTableFromQuery(string camlQry, SPList theList) {
  SPQuery listQry = new SPQuery();  
  listQry.Query = camlQry;  
  SPListItemCollection listItems = theList.GetItems(listQry);  
  return listItems.GetDataTable();
}

protected void BuildDataSet() {  
  // get SPList objects for the lists in questions ... left as an exercise for the dev -- call them list1, list2, and list3  
  string camlQry = "the CAML necessary to retreive the ites from list1";  
  DataTable table1 = GetDataTable(camlQry, list1);  
  table1.TableName = "Table1";  
  camlQry = "the CAML necessary to retreive the ites from list2";  
  DataTable table2 = GetDataTable(camlQry, list2);  
  table1.TableName = "Table2";  
  camlQry = "the CAML necessary to retreive the ites from list3";  
  DataTable table3 = GetDataTable(camlQry, list3);  
  table1.TableName = "Table3";  

  // now build the DataSet
  DataSet ds = new DataSet();  
  ds.Tables.Add(table1);  
  ds.Tables.Add(table2);  
  ds.Tables.Add(table3);  
  ds.Relations.Add("Table1_2", ds.Tables["Table1"].Columns["FieldA"], ds.Tables["Table2"].Columns["FieldA"]);  
  ds.Relations.Add("Table2_3", ds.Tables["Table2"].Columns["FieldB"], ds.Tables["Table3"].Columns["FieldB"]);  

  // now you can do something with these, like store them in the web part class and bind them to repeaters in the web part's Render() method
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文