如何将相关表添加到数据网格视图 [英] how to add related tables to data grid view

查看:77
本文介绍了如何将相关表添加到数据网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个具有一对多关系的表.我需要用相关表的内容填充相关的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


这篇关于如何将相关表添加到数据网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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