如何在dataTable中而不是dataSet中合并两个查询结果 [英] How to combine two query results in a dataTable not in a dataSet

查看:74
本文介绍了如何在dataTable中而不是dataSet中合并两个查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有两个这样的查询

选择* from sample1
选择* from sample2

我想在单个dataTable中得到结果.
当我运行此查询时,我在两个网格中得到结果.我希望它在单个网格中.

Hi All,

I have two queries like this

select *from sample1
select *from sample2

I would like to get the result in a single dataTable.
When I run this query I get the result in two grids. I want this to be in a single grid.

推荐答案



不能通过连接表或类似方法来完成此操作,

Hi,

Cant this be done by joining the tables or like,

select * from sample1,sample2 



这不是2个查询并联接数据表的简单方法吗?



Wouldnt this be the easy way instead of 2 queries and join data tables?


亲爱的朋友,

如果数据库中两个表中的列数相同,则使用
Dear Friend,

If the no of columns in both the tables from the database are same then go for
DataTable.Merge()

功能将结果放入一个数据表中.

请点击链接以获取更多信息:- http://msdn.microsoft.com/zh-cn/library/system.data.datatable.merge.aspx [

functionality to get the result into one datatable.

Please follow link for more clarity:- http://msdn.microsoft.com/en-us/library/system.data.datatable.merge.aspx[^]

I hope this will help you out.

Thanks


您可以在SQL中使用UNION或UNION ALL命令.

有关详细信息,请检查以下链接

http://blog .sqlauthority.com/2009/03/11/sql-server-difference-between-union-vs-union-all-optimal-performance-comparison/ [
You can use UNION or UNION ALL command in SQL.

For detailed information check the following link

http://blog.sqlauthority.com/2009/03/11/sql-server-difference-between-union-vs-union-all-optimal-performance-comparison/[^]

I hope this will help you. If this solution works for you then accept this answer otherwise revert back to me


这篇关于如何在dataTable中而不是dataSet中合并两个查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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