GridView,DataSet中的父子表

时间:2020-11-26 01:02:07

I have a GridView control which has a DataSet as a datasource. The dataset contains a parent child relation between two tables, Publications and Owner. When iterating through the dataset creating each row of the gridview, how do I access the data in the child table so that I can display it?

我有一个GridView控件,它有一个DataSet作为数据源。数据集包含两个表(出版物和所有者)之间的父子关系。在遍历创建gridview的每一行的数据集时,如何访问子表中的数据以便我可以显示它?

Thanks R.

1 个解决方案

#1


R,

I've been looking around for a best approach to this myself today. If it was a low-traffic site where performance didn't matter, you could grab the data from the parent table first and then use inline method(s) passing the ID to grab the child data. Not very efficient though.

我今天一直在寻找最佳方法。如果它是一个性能不高的低流量站点,您可以先从父表中获取数据,然后使用内联方法传递ID来获取子数据。虽然不是很有效率。

Another approach would be to create a class with properties representing fields of parent and child tables. Then return a list of objects representing this class to bind to.

另一种方法是创建一个具有表示父表和子表字段的属性的类。然后返回表示要绑定到的类的对象列表。

I'm considering an ADO.NET approach for my particular situation - making use of a DataSet and the DataRelation class. Basically, we populate a single DataSet with the related tables and use the DataRelation class as described here:

我正在考虑针对我的特定情况采用ADO.NET方法 - 使用DataSet和DataRelation类。基本上,我们使用相关表填充单个DataSet,并使用DataRelation类,如下所述:

http://www.codeguru.com/csharp/.net/net_data/datagrid/article.php/c10947

Anthony :-)

#1


R,

I've been looking around for a best approach to this myself today. If it was a low-traffic site where performance didn't matter, you could grab the data from the parent table first and then use inline method(s) passing the ID to grab the child data. Not very efficient though.

我今天一直在寻找最佳方法。如果它是一个性能不高的低流量站点,您可以先从父表中获取数据,然后使用内联方法传递ID来获取子数据。虽然不是很有效率。

Another approach would be to create a class with properties representing fields of parent and child tables. Then return a list of objects representing this class to bind to.

另一种方法是创建一个具有表示父表和子表字段的属性的类。然后返回表示要绑定到的类的对象列表。

I'm considering an ADO.NET approach for my particular situation - making use of a DataSet and the DataRelation class. Basically, we populate a single DataSet with the related tables and use the DataRelation class as described here:

我正在考虑针对我的特定情况采用ADO.NET方法 - 使用DataSet和DataRelation类。基本上,我们使用相关表填充单个DataSet,并使用DataRelation类,如下所述:

http://www.codeguru.com/csharp/.net/net_data/datagrid/article.php/c10947

Anthony :-)