如何将相关表添加到数据网格视图

问题描述:

我有两个具有一对多关系的表.我需要用相关表的内容填充相关的ID字段.您可以让我知道如何实现此目标.

I have two tables with one to many relation. I need to populate the related id field with the contents of the related table. Can you let me know how can I achieve this.

您可以使用嵌套的网格视图来实现.父网格视图将显示所有主记录.嵌套的网格视图将显示所有子记录.父行应该具有与其关联的数据键,以便唯一地标识其子记录.
You can achieve this by using nested grid views. The parent grid views will display all the master records. The nested grid view will display all the child records. The parent row should have datakeys associated with it so as to uniquely identify its child records.


我相信您需要研究SQL连接.这是有关SQL连接的上一篇文章.学习吧.

SQL联接的可视表示形式 [
I believe you need to study SQL Joins. Here is a previous article regarding SQL Joins. Study it.

Visual Representation of SQL Joins[^]

Regards,
Eduard


首先,您需要基于主键和外键联接两个表,使用相同的查询从数据库中查询.
将从数据库查询的样本保存到数据表中
最后,您需要将数据表绑定到gridview
first you need to join two tables based on the primary key and foreign key, use the same query to query from the database.
save the sample queried from database in datatable
and finally you need to to bind the datatable to the gridview