将数据从两个不同的表绑定到一个GridView. [英] binding data to one GridView from two different tables.

查看:94
本文介绍了将数据从两个不同的表绑定到一个GridView.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我有一个GridView,我要从两个不同的表中获取数据.比如说table1和table2.

我编写了一个存储过程,该过程返回两个表.

现在,我想在一个GridView中添加这两个表数据.

我该怎么办??

在此先感谢.
:-)

解决方案

如果这两个表相似,则可以使用UNION子句.
如果它们具有外键关系,则可以将两个表结合在一起,然后一起显示.

否则,我不太确定为什么要在网格中一起显示不相关的数据.


将这两个表数据添加到一个GridView中
方法之一:创建一个新的数据表-第三个.从第一个&其次.
首先添加数据表1和&的列.然后是datatable2.接下来,将每个表中的数据添加到该表中.
完成后,将新的数据表用作网格的数据源.

对于类似的架构数据表,请使用 DataTable.Merge方法 [ ^ ]

阅读本文

http://www.aspnettutorials.com/tutorials/database/bind-mult- table-gridview-asp4.aspx [ ^ ]
http://www.aspdotnetcodes.com/Parent_Child_GridView_DetailsView.aspx [ 解决方案

If thse two tables are similar, you can use a UNION clause.
If they have a foreign key relationship, you could join the two tables and then display them together.

Otherwise, I''m not quite sure why you would want to display unrelated data together in a grid.


add this two tables data in one GridView
One of the ways: Create a new datatable - third one. Add data from first & second to it.
First add columns of datatable 1 & then datatable 2. Next, add data from each tables to this one.
Once done, use the new datatable as a datasource for grid.

For a similar schema datatable, use
DataTable.Merge Method[^]


Read this article

http://www.aspnettutorials.com/tutorials/database/bind-mult-table-gridview-asp4.aspx[^]
http://www.aspdotnetcodes.com/Parent_Child_GridView_DetailsView.aspx[^]


这篇关于将数据从两个不同的表绑定到一个GridView.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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