数据集 - 如何从子表中获取数据? [英] Dataset - How to get data from a child table?

查看:82
本文介绍了数据集 - 如何从子表中获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我已经填充了一个包含多个表格的数据集,比如说 - Roster,Agent和一些

更多。数据集用于填充带有一些班次信息的列表视图。


我认为我在数据集中成功创建了一种关系。在

花名册表格中有一个AgentKey。可以链接到Agent表。

我正在尝试做的是,当我循环通过数据集时,我想要

显示代理表中列表视图中代理的名称。


我在帮助或互联网上查看,我找到的答案是我必须循环

通过Agent表...因为可能有几百个名册记录可能会返回
,而且我还需要以相同的

方式显示其他几个列,我担心这个过程可能会很慢。


所以我想知道有没有更好的方法呢?


这是'我的代码:


Dim daRoster,daAgent As SqlDataAdapter

Dim rowRoster As DataRow


daRoster =新的SqlDataAdapter(sSQL,Conn)

daAgent =新的SqlDataAdapter(" Select Agent_Key,Name,from Agent",Conn)

dsRoster.Relations.Add(" ; AgttoR",

dsRoster.Tables(" Agent")。Co lumns(QUOT; Agent_Key"),dsRoster.Tables

("名册")色谱柱(QUOT; Agent_Key")。)


。对于每一个rowRoster在dsRoster.Tables(QUOT;名册")。行

itmx =新的ListViewItem

itmx.Text = rowRoster(QUOT; Agent_Roster_Key")

itmx.SubItems.Add(rowRoster(" Name")''****这不是
工作...

lvwRoster.Items.Add( itmx)

下一页

谢谢〜



解决方案

这是我过去的一段相似的代码(几乎与

相同)。当您将光标移动到父记录上时,子网格会自动更新子表

信息。父母

网格也会扩展到相关的子列表。


Dim ds As DataSet = New DataSet

ds.Clear()

adpCustomers.Fill(ds," Customers")

adpOrders.Fill(ds," Orders")

adpOrderDetails.Fill( ds,订单详细信息)

ds.Relations.Add(" CustomersToOrders",_

ds.Tables(" Customers")。列(") CustomerID"),_

ds.Tables(" Orders")。Columns(" CustomerID"))

ds.Relations.Add(" ; OrdersToOrderDetails",_

ds.Tables(" Orders")。Columns(" OrderID"),_

ds.Tables(" Order Details") .Columns(" OrderID"))

dgCustomers.DataSource = ds

dgCustomers.DataMember =" Customers"


dgOrders.DataSource = ds

dgOrders.DataMember =" Customers.CustomersToOrders"


dgOrderDetails.Data来源= ds

dgOrderDetails.DataMember =

" Customers.CustomersToOrders.OrdersToOrderDeta ils"

希望这就是你要找的东西。


比尔,


感谢您的帮助〜您的代码的第一部分非常类似于我的但是

我需要将数据填充到listview中,每行记录将在

一行,而不是分层,例如:


代理商名称/班次日期/班次开始/班次结束

凯/ 01-11-2005 / 10.00 / 18.00


代理名称链接到Agent表(子),其余是名册

表(父)。而且我不知道如何从

a数据集中获取代理名称(子表).....


如果您需要更多信息,请让我知道〜


TIA





< bi ***** ****@gmail.com>在消息中写道

news:11 ********************** @ g47g2000cwa.googlegr oups.com ...

这是我过去的一段相似的代码(几乎相同)。当您将光标移动到父记录上时,子网格会自动更新子表
信息。父母
网格也扩展为相关的子列表。

Dim ds As DataSet = New DataSet
ds.Clear()
adpCustomers.Fill(ds,"客户")
adpOrders.Fill(DS,"订单")
adpOrderDetails.Fill(DS,"订单细节QUOT;)

ds.Relations.Add(" CustomersToOrders" ;, _
ds.Tables(QUOT;客户和QUOT;)色谱柱(QUOT;客户id")。,_
ds.Tables(QUOT;订单")色谱柱(QUOT;客户id")。)

ds.Relations.Add(" OrdersToOrderDetails",_
ds.Tables(" Orders")。Columns(" OrderID"),_
ds.Tables( 订单详细信息。列(OrderID))

dgCustomers.DataSource = ds
dgCustomers.DataMember =" Customers"

dgOrders。 DataSource = ds
dgOrders.DataMember =" Customers.CustomersToOrders"
dgOrderDetails.DataSource = ds
dgOrderDetails.DataMember =
" Customers.CustomersToOrders.OrdersToOrderDeta ils"

希望它是您正在寻找的。


凯,

我第一次看不到比尔给你正确答案。现在我看到他了>
不需要我在后一篇文章中给他的样本。


我想写给你的是,你不会使用

数据对象列表视图。 (System.data)。那就是DataGrid和

DataGridView的最优化。列表视图只会给你大部分时间所有人b / b
迟早会遇到很多麻烦。


然而如果你坚持,我认为甚至关于你写给比尔的内容,TreeView可以更好




你可以从每个关系中得到它的孩子的数据流,如果是

那些存在。


只是我的想法,


Cor


Hi all,

I have populated a dataset with several tables, say - Roster, Agent and few
more . The dataset is used to populated a listview with some shift info..

I think I''m sucessfully created a relationship in the dataset. In the
Roster table there''s an "AgentKey" which can be linked to the Agent table.
What I''m tryting to do is, while I''m looping thru the dataset, I want to
show the Name of an Agent in the listview from the Agent table.

I have a look on the help or internet, the answer I found is I have to loop
thru the Agent table... since there may be couple hundreds Roster record may
be returned, and I also need to show several other columns in the same
manner, I''m worry the process may be pretty slow.

So I''m wondering is there a better way to do it?

Here''s my code:

Dim daRoster, daAgent As SqlDataAdapter
Dim rowRoster As DataRow

daRoster = New SqlDataAdapter(sSQL, Conn)
daAgent = New SqlDataAdapter("Select Agent_Key, Name, from Agent", Conn)
dsRoster.Relations.Add("AgttoR",
dsRoster.Tables("Agent").Columns("Agent_Key"), dsRoster.Tables
("Roster").Columns("Agent_Key"))

For Each rowRoster In dsRoster.Tables("Roster").Rows
itmx = New ListViewItem
itmx.Text = rowRoster("Agent_Roster_Key")
itmx.SubItems.Add(rowRoster("Name") ''**** this doesn''t
work ...
lvwRoster.Items.Add(itmx)
Next
Thanks~

Kay

解决方案

Here is one similar piece of code I have from the past (almost the
same). The child Grids automatically update with child table
information when you move the cursor on parent records. Also the parent
grid expands into related child lists.

Dim ds As DataSet = New DataSet
ds.Clear()
adpCustomers.Fill(ds, "Customers")
adpOrders.Fill(ds, "Orders")
adpOrderDetails.Fill(ds, "Order Details")
ds.Relations.Add("CustomersToOrders", _
ds.Tables("Customers").Columns("CustomerID"), _
ds.Tables("Orders").Columns("CustomerID"))

ds.Relations.Add("OrdersToOrderDetails", _
ds.Tables("Orders").Columns("OrderID"), _
ds.Tables("Order Details").Columns("OrderID"))

dgCustomers.DataSource = ds
dgCustomers.DataMember = "Customers"

dgOrders.DataSource = ds
dgOrders.DataMember = "Customers.CustomersToOrders"

dgOrderDetails.DataSource = ds
dgOrderDetails.DataMember =
"Customers.CustomersToOrders.OrdersToOrderDeta ils"
Hope it''s what you are looking for.


Hi Bill,

Thanks for your help~ the first bit of your code is very similar to mine but
I need to populate the data into a listview and the each record will be in
one row, rather than in hierarchal, for example:

Agent Name/Shift Date/Shift Start/Shift End
Kay/01-11-2005/10.00/18.00

Agent Name is linked to Agent table(child), the rest are Roster
table(parent). And I don''t know how to get the Agent Name(child table) from
a dataset.....

If you need more info please let me know~

T.I.A.

Kay

<bi*********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...

Here is one similar piece of code I have from the past (almost the
same). The child Grids automatically update with child table
information when you move the cursor on parent records. Also the parent
grid expands into related child lists.

Dim ds As DataSet = New DataSet
ds.Clear()
adpCustomers.Fill(ds, "Customers")
adpOrders.Fill(ds, "Orders")
adpOrderDetails.Fill(ds, "Order Details")
ds.Relations.Add("CustomersToOrders", _
ds.Tables("Customers").Columns("CustomerID"), _
ds.Tables("Orders").Columns("CustomerID"))

ds.Relations.Add("OrdersToOrderDetails", _
ds.Tables("Orders").Columns("OrderID"), _
ds.Tables("Order Details").Columns("OrderID"))

dgCustomers.DataSource = ds
dgCustomers.DataMember = "Customers"

dgOrders.DataSource = ds
dgOrders.DataMember = "Customers.CustomersToOrders"

dgOrderDetails.DataSource = ds
dgOrderDetails.DataMember =
"Customers.CustomersToOrders.OrdersToOrderDeta ils"
Hope it''s what you are looking for.



Kay,

I first did not see that Bill gave you the correct answer.And now I see he
does not need the sample I have given him in a latter post.

What I wanted to write to you was, that you would benefit not using the
listview for data-objects. (System.data). In that is the DataGrid and the
DataGridView optimalized. The listview will give you only as mostly all who
tried this sooner or later a lot of trouble.

However if you persist, while I think that even the TreeView can be better
about what you wrote to Bill.

You can get from every datarow with relations its childs and it parent if
those exist.

Just my thought,

Cor


这篇关于数据集 - 如何从子表中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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