[英]When using vb.net I need to join 2 datatables to just 1 gridview
I have been searching through a lot of different forums, but havent found the help I am looking for, so here we go. 我一直在搜索许多不同的论坛,但还没有找到我所需要的帮助,因此我们开始吧。
First of all I should inform you that I am well aware, that 1 solution could be to do a SQL join in my sql statement, however this is not so easy as I am using 2 different tables from 2 different databases. 首先,我应该通知您,我很清楚,一种解决方案可能是在我的sql语句中执行SQL连接,但是,这并不容易,因为我要使用来自2个不同数据库的2个不同表。 So I am interesting in hearing in another solution.
因此,我很高兴听到另一种解决方案。
As it is now, I have made 2 queries, and made 2 datatables, and 2 gridviews. 现在,我已经进行了2个查询,并完成了2个数据表和2个gridview。 I have succeeded in binding the data in the 2 gridviews, and now I kinda want to "merge" them based on 1 column that they share.
我已经成功地将数据绑定到2个gridview中,现在我有点想根据它们共享的1列“合并”它们。
How to do this in VB.net I don't know. 我不知道如何在VB.net中执行此操作。
Basically I have 1 table in the database dbo_db_Test_Palle
on the server OKPalle
. 基本上我在服务器
OKPalle
的数据库dbo_db_Test_Palle
有1个表。 From this I take the following columns and put into my datatable dt and bind to gridview 1. 由此,我将以下各列放入数据表dt中,并绑定到gridview 1。
| Name | ID | Organisation |
In another datatable (dt2) from dbo_db_Test_Palle2
from the server NOTokPalle
I take the following columns and put into dt2, and bind to Gridview 2. 在另一个数据表(DT2)从
dbo_db_Test_Palle2
从服务器NOTokPalle
我采取以下的列和投入DT2,以及结合的GridView 2。
| Nickname | City | Hobby | ID
What I would like to show in just one GridView
is: 我只想在一个
GridView
中显示:
| Name | ID | Organisation | Nickname | City | Hobby |
So basically I wish to add City
and Hobby
columns, from dt2
to dt
, where the posts with ID matches (others I just leave blank). 因此,基本上,我希望添加从
dt2
到dt
City
和Hobby
列,其中ID匹配的帖子匹配(其他我只保留空白)。
I really hope someone out here can help me. 我真的希望这里有人可以帮助我。
Something like this, but it's been a while since I've done this, you might need to hack around with it a little. 像这样的东西,但是自从我这样做已经有一段时间了,您可能需要稍微修改一下。
Dim ds As New DataSet
ds.Tables.Add(dt)
ds.Tables.Add(dt2)
ds.Relations.Add("rel", dt2.Columns("ID"), dt.Columns("ID"), False)
dt.Columns.Add("Nickname", GetType(System.String), "Parent.Nickname")
dt.Columns.Add("City", GetType(System.String), "Parent.City")
dt.Columns.Add("Hobby", GetType(System.String), "Parent.Hobby")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.