在 C# 中将一个 DataView 添加到另一个 DataView

发布于 2024-09-06 12:38:07 字数 392 浏览 1 评论 0原文

我需要将两个 DataView 添加在一起以获得一个可以绑定到 Repeater 的 Dataview。

我正在插入其他人的 API,因此我无法更改在 SQL 级别检索数据的方式。

所以本质上我想这样做:

DataView dView1 = getActiveModules();
DataView dView2 = getInactiveModules();

ModuleView = dView1 + dView2;

rptModules.DataSource = ModuleView.Tables[0];
rptModules.DataBind();

视图的两个模式是相同的,只是检索活动和非活动模块。

有什么想法吗?

谢谢。

I need to add two DataViews together to have one Dataview that can then be bound to a Repeater.

I am plugging into someone else's API so I can't change the way the data is retreived at the SQL Level.

So essentially I want to do this:

DataView dView1 = getActiveModules();
DataView dView2 = getInactiveModules();

ModuleView = dView1 + dView2;

rptModules.DataSource = ModuleView.Tables[0];
rptModules.DataBind();

The two schemas for the views are identical just retrieving active and inactive modules.

Any ideas?

Thanks.

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

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

发布评论

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

评论(2

给妤﹃绝世温柔 2024-09-13 12:38:07

您可以合并您的数据视图,例如...

System.Data.DataView dv = new System.Data.DataView();
System.Data.DataView dv1 = new System.Data.DataView();
dv.Table.Merge(dv1.Table);

you can merge your dataview like...

System.Data.DataView dv = new System.Data.DataView();
System.Data.DataView dv1 = new System.Data.DataView();
dv.Table.Merge(dv1.Table);
清旖 2024-09-13 12:38:07

您可以轻松地将两个视图(数据表)组合/合并为一个数据表。

示例语法

    Dim a As DataView
    Dim b As DataView

    a.Table.Merge(b.Table)

    Dim c As New DataView
    c.Table.Merge(a.Table) 'might generate error because c.Table is null

来自 http://msdn.microsoft.com /en-us/library/system.data.datatable.merge.aspx

DataTable.Merge Method 将指定的DataTable与当前的DataTable合并
数据表。

Merge方法用于合并两个
DataTable 对象主要有
类似的模式。合并通常是
在客户端应用程序上使用
纳入最新的更改
数据源到现有的
数据表。这允许客户端
申请刷新
包含最新数据的 DataTable
数据源。

合并操作考虑到
只有原始表和表
被合并。子表不是
受影响或包含在内。如果一个表有
一个或多个子表,定义为
每个孩子都是关系的一部分
表必须单独合并。

You can easily combine/merge the two views (data tables) into one data table.

Example Syntax

    Dim a As DataView
    Dim b As DataView

    a.Table.Merge(b.Table)

    Dim c As New DataView
    c.Table.Merge(a.Table) 'might generate error because c.Table is null

From http://msdn.microsoft.com/en-us/library/system.data.datatable.merge.aspx

DataTable.Merge Method Merge the specified DataTable with the current
DataTable.

The Merge method is used to merge two
DataTable objects that have largely
similar schemas. A merge is typically
used on a client application to
incorporate the latest changes from a
data source into an existing
DataTable. This allows the client
application to have a refreshed
DataTable with the latest data from
the data source.

The merge operation takes into account
only the original table, and the table
to be merged. Child tables are not
affected or included. If a table has
one or more child tables, defined as
part of a relationship, each child
table must be merged individually.

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